Spaces:
Runtime error
Runtime error
Update app/email_utils.py
Browse files- app/email_utils.py +7 -7
app/email_utils.py
CHANGED
|
@@ -7,6 +7,10 @@ def send_verification_email(to_email, username, token):
|
|
| 7 |
from_email = os.getenv("EMAIL_HOST_USER")
|
| 8 |
app_password = os.getenv("EMAIL_HOST_PASSWORD")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
subject = "Verify your account"
|
| 12 |
verification_link = f"https://webcodelab-ai-resume-ranker-api.hf.space/verify/{token}"
|
|
@@ -24,18 +28,14 @@ def send_verification_email(to_email, username, token):
|
|
| 24 |
msg['From'] = from_email
|
| 25 |
msg['To'] = to_email
|
| 26 |
msg['Subject'] = subject
|
| 27 |
-
|
| 28 |
msg.attach(MIMEText(body, 'plain'))
|
| 29 |
|
| 30 |
try:
|
| 31 |
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
|
| 32 |
server.login(from_email, app_password)
|
| 33 |
server.send_message(msg)
|
| 34 |
-
print(f"
|
| 35 |
return True
|
| 36 |
except Exception as e:
|
| 37 |
-
print(
|
| 38 |
-
|
| 39 |
-
traceback.print_exc()
|
| 40 |
-
return False
|
| 41 |
-
|
|
|
|
| 7 |
from_email = os.getenv("EMAIL_HOST_USER")
|
| 8 |
app_password = os.getenv("EMAIL_HOST_PASSWORD")
|
| 9 |
|
| 10 |
+
if not from_email or not app_password:
|
| 11 |
+
error_msg = f"Missing email env vars. EMAIL_HOST_USER={from_email}, EMAIL_HOST_PASSWORD={'SET' if app_password else 'MISSING'}"
|
| 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}"
|
|
|
|
| 28 |
msg['From'] = from_email
|
| 29 |
msg['To'] = to_email
|
| 30 |
msg['Subject'] = subject
|
|
|
|
| 31 |
msg.attach(MIMEText(body, 'plain'))
|
| 32 |
|
| 33 |
try:
|
| 34 |
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
|
| 35 |
server.login(from_email, app_password)
|
| 36 |
server.send_message(msg)
|
| 37 |
+
print(f"✅ Email sent to {to_email}")
|
| 38 |
return True
|
| 39 |
except Exception as e:
|
| 40 |
+
print("❌ Email error:", str(e))
|
| 41 |
+
return {"error": str(e)}
|
|
|
|
|
|
|
|
|