AI-Resume-Ranker-API / app /email_utils.py
webcodelab's picture
Update app/email_utils.py
d7d649f verified
Raw
History Blame Contribute Delete
2.37 kB
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)}