Spaces:
Runtime error
Runtime error
Update app/email_utils.py
Browse files- app/email_utils.py +28 -20
app/email_utils.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
| 1 |
-
import smtplib
|
| 2 |
-
from email.mime.text import MIMEText
|
| 3 |
-
from email.mime.multipart import MIMEMultipart
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
def send_verification_email(to_email, username, token):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
if not
|
| 11 |
-
error_msg = f"Missing email
|
| 12 |
-
print("", error_msg)
|
| 13 |
return {"error": error_msg}
|
| 14 |
|
| 15 |
subject = "Verify your account"
|
| 16 |
verification_link = f"https://webcodelab-ai-resume-ranker-api.hf.space/verify/{token}"
|
|
|
|
| 17 |
body = f"""
|
| 18 |
Hi {username},
|
| 19 |
|
|
@@ -24,19 +23,28 @@ def send_verification_email(to_email, username, token):
|
|
| 24 |
If you didn't sign up, you can ignore this email.
|
| 25 |
"""
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
try:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
-
print("
|
| 42 |
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
def send_verification_email(to_email, username, token):
|
| 5 |
+
api_key = os.getenv("RESEND_API_KEY")
|
| 6 |
+
from_email = os.getenv("RESEND_SENDER")
|
| 7 |
|
| 8 |
+
if not api_key or not from_email:
|
| 9 |
+
error_msg = f"Missing email config. RESEND_API_KEY={'SET' if api_key else 'MISSING'}, RESEND_SENDER={from_email}"
|
| 10 |
+
print("❌", error_msg)
|
| 11 |
return {"error": error_msg}
|
| 12 |
|
| 13 |
subject = "Verify your account"
|
| 14 |
verification_link = f"https://webcodelab-ai-resume-ranker-api.hf.space/verify/{token}"
|
| 15 |
+
|
| 16 |
body = f"""
|
| 17 |
Hi {username},
|
| 18 |
|
|
|
|
| 23 |
If you didn't sign up, you can ignore this email.
|
| 24 |
"""
|
| 25 |
|
| 26 |
+
data = {
|
| 27 |
+
"from": f"WebCodeLab <{from_email}>",
|
| 28 |
+
"to": [to_email],
|
| 29 |
+
"subject": subject,
|
| 30 |
+
"text": body
|
| 31 |
+
}
|
| 32 |
|
| 33 |
try:
|
| 34 |
+
response = requests.post(
|
| 35 |
+
"https://api.resend.com/emails",
|
| 36 |
+
headers={
|
| 37 |
+
"Authorization": f"Bearer {api_key}",
|
| 38 |
+
"Content-Type": "application/json"
|
| 39 |
+
},
|
| 40 |
+
json=data
|
| 41 |
+
)
|
| 42 |
+
if response.status_code == 200:
|
| 43 |
+
print(f" Email sent to {to_email}")
|
| 44 |
+
return True
|
| 45 |
+
else:
|
| 46 |
+
print(" Resend API error:", response.status_code, response.text)
|
| 47 |
+
return {"error": response.text}
|
| 48 |
except Exception as e:
|
| 49 |
+
print(" Unexpected error:", str(e))
|
| 50 |
return {"error": str(e)}
|