import sendgrid from sendgrid.helpers.mail import Mail from app.core.config import settings class EmailService: def __init__(self): self.sg = sendgrid.SendGridAPIClient(api_key=settings.sendgrid_api_key) self.from_email = settings.from_email async def send_welcome_email(self, to_email: str, user_name: str): message = Mail( from_email=self.from_email, to_emails=to_email, subject="Welcome to our platform!", html_content=f"""
Thank you for joining our platform. We're excited to have you on board!
Get started by exploring our features and creating your first project.
""" ) try: response = self.sg.send(message) return response.status_code == 202 except Exception as e: print(f"Error sending email: {e}") return False async def send_newsletter_signup_confirmation(self, to_email: str): message = Mail( from_email=self.from_email, to_emails=to_email, subject="Newsletter Subscription Confirmed", html_content="""Thank you for subscribing to our newsletter.
You'll receive the latest updates, tips, and product announcements.
""" ) try: response = self.sg.send(message) return response.status_code == 202 except Exception as e: print(f"Error sending email: {e}") return False async def send_contact_confirmation(self, to_email: str, name: str): message = Mail( from_email=self.from_email, to_emails=to_email, subject="Contact Form Received", html_content=f"""We've received your message and will get back to you within 24 hours.
Our team is reviewing your inquiry and will provide a detailed response soon.
""" ) try: response = self.sg.send(message) return response.status_code == 202 except Exception as e: print(f"Error sending email: {e}") return False async def send_contact_notification(self, name: str, email: str, company: str, message: str): admin_message = Mail( from_email=self.from_email, to_emails="admin@example.com", # Should come from settings subject=f"New Contact Form Submission from {name}", html_content=f"""Name: {name}
Email: {email}
Company: {company or 'Not provided'}
Message:
{message}
""" ) try: response = self.sg.send(admin_message) return response.status_code == 202 except Exception as e: print(f"Error sending email: {e}") return False async def send_sales_inquiry_confirmation(self, to_email: str, name: str): message = Mail( from_email=self.from_email, to_emails=to_email, subject="Sales Inquiry Received", html_content=f"""We've received your sales inquiry and our team will contact you within 2 business hours.
In the meantime, feel free to explore our documentation and resources.
""" ) try: response = self.sg.send(message) return response.status_code == 202 except Exception as e: print(f"Error sending email: {e}") return False async def send_sales_inquiry_notification(self, name: str, email: str, company: str, employees: str, use_case: str, message: str): sales_message = Mail( from_email=self.from_email, to_emails="sales@example.com", # Should come from settings subject=f"New Sales Inquiry from {company}", html_content=f"""Name: {name}
Email: {email}
Company: {company}
Company Size: {employees}
Use Case: {use_case}
Additional Message:
{message or 'None provided'}
""" ) try: response = self.sg.send(sales_message) return response.status_code == 202 except Exception as e: print(f"Error sending email: {e}") return False