diff --git a/app/notifications/google/__init__.py b/app/notifications/google/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/notifications/google/google_mailer.py b/app/notifications/google/google_mailer.py new file mode 100644 index 0000000..d9b60a0 --- /dev/null +++ b/app/notifications/google/google_mailer.py @@ -0,0 +1,42 @@ +import smtplib +import ssl +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +from app.utils.logger import logger + + +def send_email_google(to_email, subject, html_content, text_content=None): + SMTP_SERVER = "smtp.gmail.com" + PORT = 587 + FROM_EMAIL = "support@mermsemr.com" + APP_PASSWORD = "" # Set via env var: os.getenv("GMAIL_APP_PASSWORD") + + msg = MIMEMultipart("alternative") + msg["Subject"] = subject + msg["From"] = FROM_EMAIL + msg["To"] = to_email + + if text_content: + msg.attach(MIMEText(text_content, "plain")) + msg.attach(MIMEText(html_content, "html")) + + context = ssl.create_default_context() + + try: + with smtplib.SMTP(SMTP_SERVER, PORT) as server: + server.ehlo() + server.starttls(context=context) + server.ehlo() + server.login(FROM_EMAIL, APP_PASSWORD) + server.sendmail(FROM_EMAIL, to_email, msg.as_string()) + logger.info(f"Google email sent to {to_email}") + + except smtplib.SMTPAuthenticationError: + logger.error("Google SMTP auth failed: check FROM_EMAIL and APP_PASSWORD") + raise + except smtplib.SMTPConnectError as e: + logger.error(f"Google SMTP connection error: {e}") + raise + except Exception as e: + logger.error(f"Google SMTP send failed: {e}") + raise diff --git a/app/notifications/sendgrid/sendgrid_mailer.py b/app/notifications/sendgrid/sendgrid_mailer.py index 10ee25a..b37c643 100644 --- a/app/notifications/sendgrid/sendgrid_mailer.py +++ b/app/notifications/sendgrid/sendgrid_mailer.py @@ -5,8 +5,8 @@ from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail -@staticmethod -def test_new_mailer(): +# @staticmethod +def send_email_sendgrid(): # Replace these with your actual details SENDGRID_API_KEY = "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"