Added AWS SES email

This commit is contained in:
2026-04-26 01:11:30 -04:00
parent 8bc157b6ba
commit 86e897c54d
3 changed files with 44 additions and 2 deletions
+42
View File
@@ -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
@@ -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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"