import os from dotenv import load_dotenv import httpx import asyncio load_dotenv() # Consistent URL usage for deployment BASE_URL = os.getenv("APP_URL", "https://legal-assistant-lawbot.hf.space") # Brevo (Sendinblue) Configuration BREVO_API_KEY = os.getenv("BREVO_API_KEY", "") # Must be your verified sender in Brevo BREVO_SENDER_EMAIL = os.getenv("BREVO_SENDER_EMAIL", "vishwaroman04@gmail.com") async def send_reset_email(email: str, token: str): """Send password reset email using Brevo (Sendinblue) API""" if not BREVO_API_KEY: raise ValueError("BREVO_API_KEY missing. Please add it to Secrets.") reset_link = f"{BASE_URL}/reset-password?token={token}" html_body = f"""

Password Reset Request

Hello,

We received a request to reset your password for your Law Bot account.

Click the button below to reset your password:

Reset Password

Or copy and paste this link into your browser:

{reset_link}

If you didn't request this, you can safely ignore this email.


Law Bot India - AI Legal Assistant
https://legal-assistant-lawbot.hf.space

""" url = "https://api.brevo.com/v3/smtp/email" payload = { "sender": {"name": "Law Bot India", "email": BREVO_SENDER_EMAIL}, "to": [{"email": email}], "subject": "Password Reset Request - Law Bot", "htmlContent": html_body } headers = { "accept": "application/json", "api-key": BREVO_API_KEY, "content-type": "application/json" } try: async with httpx.AsyncClient() as client: response = await client.post(url, json=payload, headers=headers, timeout=10.0) if response.status_code in [200, 201, 202]: print(f"✅ Email sent successfully via Brevo to {email}") return True else: error_msg = f"Brevo API Error: {response.status_code} - {response.text}" print(f"❌ {error_msg}") raise ValueError(error_msg) except Exception as e: print(f"❌ Failed to send via Brevo: {e}") raise ValueError(f"Failed to send email: {str(e)}")