Spaces:
Runtime error
Runtime error
File size: 1,947 Bytes
4b63522 ee949c5 4b63522 ee949c5 88e859d ee949c5 3be27fb 4b63522 85ba78b 4b63522 b8b0576 4b63522 ee949c5 b8b0576 ee949c5 b8b0576 ee949c5 4b63522 ee949c5 4b63522 ee949c5 3be27fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import os
import requests
def send_verification_email(to_email, username, token):
api_key = os.getenv("RESEND_API_KEY")
from_email = os.getenv("RESEND_SENDER")
if not api_key or not from_email:
error_msg = f"Missing email config. RESEND_API_KEY={'SET' if api_key else 'MISSING'}, RESEND_SENDER={from_email}"
print("❌", error_msg)
return {"error": error_msg}
subject = "Verify your account"
verification_link = f"https://webcodelab-ai-resume-ranker-api.hf.space/verify/{token}"
html_body = f"""
<html>
<body style="font-family: Arial, sans-serif; line-height: 1.6;">
<p>Hi {username},</p>
<p>Thanks for registering! Please verify your email by clicking the button below:</p>
<p>
<a href="{verification_link}" style="background-color: #007BFF; color: white; padding: 12px 20px; text-decoration: none; border-radius: 5px; display: inline-block;">
Verify Email
</a>
</p>
<p>If you didn't sign up, you can safely ignore this email.</p>
</body>
</html>
"""
data = {
"from": f"RankApply <{from_email}>",
"to": [to_email],
"subject": subject,
"html": html_body,
"text": f"Hi {username},\n\nPlease verify your account:\n{verification_link}"
}
try:
response = requests.post(
"https://api.resend.com/emails",
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
},
json=data
)
if response.status_code == 200:
print(f" Email sent to {to_email}")
return True
else:
print(" Resend API error:", response.status_code, response.text)
return {"error": response.text}
except Exception as e:
print(" Unexpected error:", str(e))
return {"error": str(e)}
|