import httpx from typing import List, Optional from ..core.config import settings class EmailService: """Email service using SMTP2GO API""" def __init__(self): self.api_key = settings.SMTP2GO_API_KEY self.api_url = settings.SMTP2GO_API_URL self.from_email = settings.EMAIL_FROM self.from_name = settings.EMAIL_FROM_NAME async def send_email( self, to_email: str, subject: str, html_body: str, text_body: Optional[str] = None ) -> dict: """ Send an email using SMTP2GO API Args: to_email: Recipient email address subject: Email subject html_body: HTML content of the email text_body: Plain text content (optional) Returns: dict: API response """ payload = { "to": [to_email], "sender": f"{self.from_name} <{self.from_email}>", "subject": subject, "html_body": html_body, } if text_body: payload["text_body"] = text_body headers = { "Content-Type": "application/json", "X-Smtp2go-Api-Key": self.api_key } async with httpx.AsyncClient() as client: response = await client.post(self.api_url, json=payload, headers=headers) return response.json() async def send_welcome_email(self, to_email: str, first_name: str) -> dict: """Send welcome email to new user""" subject = f"Welcome to {settings.APP_NAME}!" html_body = f"""
Hello {first_name},
Thank you for registering with us. Your account has been successfully created.
You can now:
If you have any questions, please don't hesitate to contact us.
Best regards,
{settings.APP_NAME}
Hello {first_name},
We have received your payment. Thank you!
Amount: £{amount:.2f}
Payment Method: {payment_method}
Membership Tier: {membership_tier}
Your membership is now active. You can access all the benefits associated with your tier.
Best regards,
{settings.APP_NAME}
Hello {first_name},
This is a friendly reminder that your {membership_tier} membership will expire on {expiry_date}.
To continue enjoying your membership benefits, please renew your membership.
Membership Tier: {membership_tier}
Annual Fee: £{annual_fee:.2f}
Expires: {expiry_date}
Please log in to your account to renew your membership.
Best regards,
{settings.APP_NAME}