import os from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail, Email, To, Content from .core import config # SendGrid Configuration SENDGRID_API_KEY = os.getenv("SENDGRID_API_KEY", "") SENDGRID_FROM_EMAIL = os.getenv("SENDGRID_FROM_EMAIL", "noreply@yourdomain.com") # Change this to your email SENDGRID_FROM_NAME = os.getenv("SENDGRID_FROM_NAME", "DocFusion AI") # Configure SendGrid sendgrid_client = None if SENDGRID_API_KEY: sendgrid_client = SendGridAPIClient(SENDGRID_API_KEY) def get_welcome_email_html(user_name: str) -> str: """Generate a themed welcome email HTML""" # Logo URL from Cloudinary (hosted) logo_url = os.getenv("LOGO_URL", "https://res.cloudinary.com/dggwdladu/image/upload/v1759913904/docfusion/docfusion_logo.png") return f""" Welcome to DocFusion AI
DocFusion AI Logo

DocFusion AI

Intelligent Document Assistant

Welcome, {user_name}! 🎉

Thank you for joining DocFusion AI! We're excited to have you on board.

With DocFusion AI, you can upload your PDF documents and interact with them using natural language. Ask questions, extract information, and gain insights from your documents effortlessly.

🚀 Getting Started:

  • Upload Documents: Start by uploading your PDF files
  • Ask Questions: Chat naturally with your documents
  • Manage Sessions: Organize documents into different sessions
  • Get Instant Answers: AI-powered responses with source references
Start Using DocFusion AI

Need help? Our support team is here for you. Just reply to this email or visit our help center.

Happy document exploring! 📚✨

© 2025 DocFusion AI. All rights reserved.

You're receiving this email because you created an account with DocFusion AI.

Update email preferences

""" async def send_welcome_email(to_email: str, user_name: str) -> bool: """Send a welcome email to a new user using SendGrid""" if not sendgrid_client: print("SendGrid API key not configured, skipping email") return True # Return True so it doesn't cause issues try: # Plain text version (fallback) text_content = f""" Welcome to DocFusion AI, {user_name}! Thank you for joining DocFusion AI! We're excited to have you on board. With DocFusion AI, you can upload your PDF documents and interact with them using natural language. Ask questions, extract information, and gain insights from your documents effortlessly. Getting Started: - Upload Documents: Start by uploading your PDF files - Ask Questions: Chat naturally with your documents - Manage Sessions: Organize documents into different sessions - Get Instant Answers: AI-powered responses with source references Visit {os.getenv('FRONTEND_URL', 'http://localhost:5173')} to get started! Need help? Our support team is here for you. Just reply to this email. Happy document exploring! © 2025 DocFusion AI. All rights reserved. """ # HTML version html_content = get_welcome_email_html(user_name) # Create SendGrid message message = Mail( from_email=Email(SENDGRID_FROM_EMAIL, SENDGRID_FROM_NAME), to_emails=To(to_email), subject=f"Welcome to DocFusion AI, {user_name}! 🎉", plain_text_content=Content("text/plain", text_content), html_content=Content("text/html", html_content) ) # Send email using SendGrid response = sendgrid_client.send(message) print(f"Welcome email sent successfully to {to_email} (Status: {response.status_code})") return True except Exception as e: print(f"Failed to send welcome email: {e}") # Don't raise the exception - just log it and continue # This prevents email failures from breaking registration return False