Spaces:
Runtime error
Runtime error
File size: 2,369 Bytes
4b63522 ee949c5 4b63522 f69404d ee949c5 d7d649f 88e859d f69404d ee949c5 3be27fb 4b63522 85ba78b 4b63522 b8b0576 4b63522 ee949c5 b8b0576 ee949c5 b8b0576 ee949c5 4b63522 ee949c5 f69404d ee949c5 f69404d ee949c5 4b63522 f69404d 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 58 59 60 61 62 63 64 65 66 | import os
import requests
def send_verification_email(to_email, username, token):
# Check if we're in development mode
dev_mode = os.getenv("EMAIL_DEV_MODE", "false").lower() == "true"
if dev_mode:
# Development mode: just print the verification link
verification_link = f"https://webcodelab-ai-resume-ranker-api.hf.space/verify/{token}"
print(f"π [DEV MODE] Verification link for {to_email}: {verification_link}")
return True
api_key = os.getenv("RESEND_API_KEY")
from_email = os.getenv("RESEND_SENDER", "noreply@webcodelab.com.ng") # Use your verified domain
if not api_key:
error_msg = f"Missing email config. RESEND_API_KEY={'SET' if api_key else 'MISSING'}"
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)}
|