diff --git a/app/api/services/base_service.py b/app/api/services/base_service.py index fc0bce7..af98abc 100644 --- a/app/api/services/base_service.py +++ b/app/api/services/base_service.py @@ -18,6 +18,7 @@ import jwt import requests import redis import json +from app.notifications.aws.aws_mailer import send_email_ses class BaseService: @@ -108,27 +109,35 @@ class BaseService: sender_password = BaseService.SEND_EMAIL_PASS receiver_email = signup_email subject = "Reset Password Completed" - body = msg_body - msg = MIMEMultipart() - msg['Subject'] = subject - msg['From'] = sender_email - msg['To'] = receiver_email - msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content + send_email_ses( + to_email=receiver_email, + subject=subject, + html_content=html_body + ) - try: - # For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL) - # For other providers, consult their documentation for SMTP server and port - 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 + # + # body = msg_body + # + # msg = MIMEMultipart() + # msg['Subject'] = subject + # msg['From'] = sender_email + # msg['To'] = receiver_email + # 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) + # # For other providers, consult their documentation for SMTP server and port + # 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 def send_resetpass_mail(signup_email, pending_uid, pending_id, firstname, lastname): @@ -206,25 +215,31 @@ class BaseService: subject = "Reset Password Email" body = msg_body - msg = MIMEMultipart() - msg['Subject'] = subject - msg['From'] = sender_email - msg['To'] = receiver_email - msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content + send_email_ses( + to_email=receiver_email, + subject=subject, + html_content=html_body + ) - try: - # For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL) - # For other providers, consult their documentation for SMTP server and port - 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 + # msg = MIMEMultipart() + # msg['Subject'] = subject + # msg['From'] = sender_email + # msg['To'] = receiver_email + # 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) + # # For other providers, consult their documentation for SMTP server and port + # 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 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" body = msg_body + html_body = f"""\ @@ -298,25 +314,31 @@ class BaseService: """ - msg = MIMEMultipart() - msg['Subject'] = subject - msg['From'] = sender_email - msg['To'] = receiver_email - msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content + send_email_ses( + to_email=receiver_email, + subject=subject, + html_content=html_body + ) - try: - # For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL) - # For other providers, consult their documentation for SMTP server and port - 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 + # msg = MIMEMultipart() + # msg['Subject'] = subject + # msg['From'] = sender_email + # msg['To'] = receiver_email + # 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) + # # For other providers, consult their documentation for SMTP server and port + # 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 @classmethod def validate_data(cls, data, schema):