Added AWS SES email

This commit is contained in:
2026-04-25 17:22:32 -04:00
parent 37b54e7390
commit 8bc157b6ba
+77 -55
View File
@@ -18,6 +18,7 @@ import jwt
import requests import requests
import redis import redis
import json import json
from app.notifications.aws.aws_mailer import send_email_ses
class BaseService: class BaseService:
@@ -108,27 +109,35 @@ class BaseService:
sender_password = BaseService.SEND_EMAIL_PASS sender_password = BaseService.SEND_EMAIL_PASS
receiver_email = signup_email receiver_email = signup_email
subject = "Reset Password Completed" subject = "Reset Password Completed"
body = msg_body
msg = MIMEMultipart() send_email_ses(
msg['Subject'] = subject to_email=receiver_email,
msg['From'] = sender_email subject=subject,
msg['To'] = receiver_email html_content=html_body
msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content )
try: #
# For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL) # body = msg_body
# For other providers, consult their documentation for SMTP server and port #
server = smtplib.SMTP('smtp.gmail.com', 587) # msg = MIMEMultipart()
# server.starttls() # Enable TLS encryption # msg['Subject'] = subject
server.login(sender_email, sender_password) # msg['From'] = sender_email
server.sendmail(sender_email, receiver_email, msg.as_string()) # msg['To'] = receiver_email
print("Email sent successfully!") # msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content
except Exception as e: #
print(f"Error sending email: {e}") # try:
logger.error(f"Error sending email: {e}") # # For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL)
finally: # # For other providers, consult their documentation for SMTP server and port
server.quit() # Close the connection # server = smtplib.SMTP('smtp.gmail.com', 587)
# # server.starttls() # Enable TLS encryption
# server.login(sender_email, sender_password)
# server.sendmail(sender_email, receiver_email, msg.as_string())
# print("Email sent successfully!")
# except Exception as e:
# print(f"Error sending email: {e}")
# logger.error(f"Error sending email: {e}")
# finally:
# server.quit() # Close the connection
@staticmethod @staticmethod
def send_resetpass_mail(signup_email, pending_uid, pending_id, firstname, lastname): def send_resetpass_mail(signup_email, pending_uid, pending_id, firstname, lastname):
@@ -206,25 +215,31 @@ class BaseService:
subject = "Reset Password Email" subject = "Reset Password Email"
body = msg_body body = msg_body
msg = MIMEMultipart() send_email_ses(
msg['Subject'] = subject to_email=receiver_email,
msg['From'] = sender_email subject=subject,
msg['To'] = receiver_email html_content=html_body
msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content )
try: # msg = MIMEMultipart()
# For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL) # msg['Subject'] = subject
# For other providers, consult their documentation for SMTP server and port # msg['From'] = sender_email
server = smtplib.SMTP('smtp.gmail.com', 587) # msg['To'] = receiver_email
# server.starttls() # Enable TLS encryption # msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content
server.login(sender_email, sender_password) #
server.sendmail(sender_email, receiver_email, msg.as_string()) # try:
print("Email sent successfully!") # # For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL)
except Exception as e: # # For other providers, consult their documentation for SMTP server and port
print(f"Error sending email: {e}") # server = smtplib.SMTP('smtp.gmail.com', 587)
logger.error(f"Error sending email: {e}") # # server.starttls() # Enable TLS encryption
finally: # server.login(sender_email, sender_password)
server.quit() # Close the connection # server.sendmail(sender_email, receiver_email, msg.as_string())
# print("Email sent successfully!")
# except Exception as e:
# print(f"Error sending email: {e}")
# logger.error(f"Error sending email: {e}")
# finally:
# server.quit() # Close the connection
def send_verify_signup_mail(signup_email, pending_uid, pending_id, firstname, lastname): def send_verify_signup_mail(signup_email, pending_uid, pending_id, firstname, lastname):
@@ -260,6 +275,7 @@ class BaseService:
subject = "Verify your MERMS(AI) Account Setup" subject = "Verify your MERMS(AI) Account Setup"
body = msg_body body = msg_body
html_body = f"""\ html_body = f"""\
<html> <html>
<head></head> <head></head>
@@ -298,25 +314,31 @@ class BaseService:
</html> </html>
""" """
msg = MIMEMultipart() send_email_ses(
msg['Subject'] = subject to_email=receiver_email,
msg['From'] = sender_email subject=subject,
msg['To'] = receiver_email html_content=html_body
msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content )
try: # msg = MIMEMultipart()
# For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL) # msg['Subject'] = subject
# For other providers, consult their documentation for SMTP server and port # msg['From'] = sender_email
server = smtplib.SMTP('smtp.gmail.com', 587) # msg['To'] = receiver_email
# server.starttls() # Enable TLS encryption # msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content
server.login(sender_email, sender_password) #
server.sendmail(sender_email, receiver_email, msg.as_string()) # try:
print("Email sent successfully!") # # For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL)
except Exception as e: # # For other providers, consult their documentation for SMTP server and port
print(f"Error sending email: {e}") # server = smtplib.SMTP('smtp.gmail.com', 587)
logger.error(f"Error sending email: {e}") # # server.starttls() # Enable TLS encryption
finally: # server.login(sender_email, sender_password)
server.quit() # Close the connection # server.sendmail(sender_email, receiver_email, msg.as_string())
# print("Email sent successfully!")
# except Exception as e:
# print(f"Error sending email: {e}")
# logger.error(f"Error sending email: {e}")
# finally:
# server.quit() # Close the connection
@classmethod @classmethod
def validate_data(cls, data, schema): def validate_data(cls, data, schema):