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"""
Hi {username},
Thanks for registering! Please verify your email by clicking the button below:
If you didn't sign up, you can safely ignore this email.
""" 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)}