Spaces:
Runtime error
Runtime error
| 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)} | |