diff --git a/.env b/.env index aa2930d..a48105a 100644 --- a/.env +++ b/.env @@ -32,6 +32,8 @@ SIMBRELLA_API_KEY="testtest-api-key-12345" # support@mermsemr.com # F7f220a7f.may12002! +# twillo recovery - BPR7DMFHP53D919YWYWB6R5F + MAIL_SERVER=smtp.gmail.com MAIL_PORT= 465 MAIL_USERNAME=message@chiefsoft.com @@ -59,4 +61,7 @@ STRIPE_CANCEL_URL="https://qa-panel.mermsemr.com/subscription" # UPLOAD PATHS UPLOAD_FOLDER="/app/uploads/DEV" -MEDIA_SERVER="https://qa-media.mermsemr.com" \ No newline at end of file +MEDIA_SERVER="https://qa-media.mermsemr.com" + +AWS_ACCESS_KEY_ID=AKIAZAI4GVFJEGM4JHET +AWS_SECRET_ACCESS_KEY=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 \ No newline at end of file diff --git a/.production.env b/.production.env index 8232114..c013e76 100644 --- a/.production.env +++ b/.production.env @@ -59,3 +59,5 @@ STRIPE_CANCEL_URL="https://panel.mermsemr.com/subscription" UPLOAD_FOLDER="/app/uploads/LIVE" MEDIA_SERVER="https://media.mermsemr.com" +AWS_ACCESS_KEY_ID=AKIAZAI4GVFJEGM4JHET +AWS_SECRET_ACCESS_KEY=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 \ No newline at end of file diff --git a/.qa.env b/.qa.env index 45a8844..bb545e8 100644 --- a/.qa.env +++ b/.qa.env @@ -60,4 +60,7 @@ START_URL_PATTERN =".devprov.mermsemr.com" # UPLOAD PATHS UPLOAD_FOLDER="/app/uploads/DEV" -MEDIA_SERVER="https://qa-media.mermsemr.com" \ No newline at end of file +MEDIA_SERVER="https://qa-media.mermsemr.com" + +AWS_ACCESS_KEY_ID=AKIAZAI4GVFJEGM4JHET +AWS_SECRET_ACCESS_KEY=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 \ No newline at end of file diff --git a/app/api/services/account.py b/app/api/services/account.py index 1df5490..5b38701 100644 --- a/app/api/services/account.py +++ b/app/api/services/account.py @@ -22,6 +22,9 @@ import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail + import datetime import jwt import random @@ -31,6 +34,9 @@ from app.config import Config import smtplib, ssl from email.message import EmailMessage +from app.notifications.aws.aws_mailer import send_email_ses + + class AccountService(BaseService): JWT_SECRET_KEY = Config.JWT_SECRET_KEY @@ -644,59 +650,55 @@ class AccountService(BaseService): @staticmethod def process_test_email(data): - logger.info(f"Email Test Enter", exc_info=True) - AccountService.test_new_mailer() - AccountService.send_register_mail('ameye@chiefsoft.com', 'pend-uid---', 100, 'olutest', 'Ameyetest') + logger.info(f"Email Test Enter 001", exc_info=True) + send_email_ses( + to_email="ameye@chiefsoft.com", + subject="Test from Merms", + html_content="Hello from AWS SES" + ) + # AccountService.test_new_mailer() + # AccountService.send_register_mail('ameye@chiefsoft.com', 'pend-uid---', 100, 'olutest', 'Ameyetest') logger.info(f"Email Test", exc_info=True) @staticmethod - def test_new_mailer(): + def test_new_mailer_old(): logger.info("test_new_mailer 000 ") # --- Email Configuration --- sender_email = "support@mermsemr.com" # Enter your email address receiver_email = "ameye@chiefsoft.com" # Enter the recipient's address # Use the App Password generated in Step 1 - app_password = "ijcl pyko pswl phra" - app_password55 = "ijclpykopswlphra" + app_password = "flhf cjjx bguv fycg" + app_password = "flhfcjjxbguvfycg" # --- Create the Email Message --- - msg = EmailMessage() - msg.set_content("This is the body of the email sent from Python.") + # msg = EmailMessage() + # msg.set_content("This is the body of the email sent from Python.") + msg = MIMEText("This is the body of my email.") msg['Subject'] = "Subject Line from Python" msg['From'] = sender_email msg['To'] = receiver_email # --- Connect to Gmail's SMTP Server and Send the Email --- smtp_server = "smtp.gmail.com" - port = 465 # For SSL - port = 587 # For non SSL + port = 587 # STARTTLS - # Create a secure SSL context - # context = ssl.create_default_context() + context = ssl.create_default_context() logger.info("test_new_mailer 003 ") try: logger.info("test_new_mailer 000 44") - # with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: with smtplib.SMTP(smtp_server, port) as server: - # server.starttls() + logger.info("test_new_mailer 000 44-1") + server.ehlo() + logger.info("test_new_mailer 000 44-2") + server.starttls(context=context) + server.ehlo() logger.info("test_new_mailer 000 55") server.login(sender_email, app_password) logger.info("test_new_mailer 000 66") server.send_message(msg) logger.info("test_new_mailer 000 77") - - logger.info("Email sent successfully!") - # msg = EmailMessage() - # msg.set_content("This is the body of the email.") - # msg['Subject'] = "Test Subject" - # msg['From'] = "sender@example.com" - # msg['To'] = "recipient@example.com" - # - # server.send_message(msg) - # print("Email sent successfully!") - except smtplib.SMTPAuthenticationError: logger.error("Authentication error: Check your username and password.") @@ -708,6 +710,85 @@ class AccountService(BaseService): logger.error(f"An unrelated error occurred: {e}") + @staticmethod + def test_new_mailer(): + + # Replace these with your actual details + SENDGRID_API_KEY = "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" + FROM_EMAIL = 'support@mermsemr.com' # Must be a verified sender in SendGrid + TO_EMAIL = 'works@chiefsoft.com' + + message = Mail( + from_email=FROM_EMAIL, + to_emails=TO_EMAIL, + subject='Sending with Twilio SendGrid is Fun', + html_content='and easy to do anywhere, even with Python' + ) + + try: + # Initialize the SendGrid client + sg = SendGridAPIClient(SENDGRID_API_KEY) + + # Send the email + response = sg.send(message) + + # Print status codes: 202 means the request was accepted for delivery + print(f"Status Code: {response.status_code}") + print(f"Body: {response.body}") + print(f"Headers: {response.headers}") + + except Exception as e: + logger.error(f"An unrelated error occurred: {e}") + + + # logger.info("test_new_mailer 000 ") + # # --- Email Configuration --- + # sender_email = "support@mermsemr.com" # Enter your email address + # receiver_email = "ameye@chiefsoft.com" # Enter the recipient's address + # # Use the App Password generated in Step 1 + # app_password = "flhf cjjx bguv fycg" + # app_password = "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" + # + # # --- Create the Email Message --- + # # msg = EmailMessage() + # # msg.set_content("This is the body of the email sent from Python.") + # msg = MIMEText("This is the body of my email.") + # msg['Subject'] = "Subject Line from Python" + # msg['From'] = sender_email + # msg['To'] = receiver_email + # + # # --- Connect to Gmail's SMTP Server and Send the Email --- + # smtp_server = "smtp.sendgrid.net" + # port = 587 # STARTTLS + # + # context = ssl.create_default_context() + # logger.info("test_new_mailer 003 ") + # try: + # logger.info("test_new_mailer 000 44") + # with smtplib.SMTP(smtp_server, port) as server: + # logger.info("test_new_mailer 000 44-1") + # server.ehlo() + # logger.info("test_new_mailer 000 44-2") + # server.starttls(context=context) + # server.ehlo() + # logger.info("test_new_mailer 000 55") + # server.login(sender_email, app_password) + # logger.info("test_new_mailer 000 66") + # server.send_message(msg) + # logger.info("test_new_mailer 000 77") + # logger.info("Email sent successfully!") + # + # except smtplib.SMTPAuthenticationError: + # logger.error("Authentication error: Check your username and password.") + # + # except smtplib.SMTPConnectError as e: + # logger.error(f"Connection error: {e}") + # except smtplib.SMTPException as e: + # logger.error(f"An unexpected SMTP error occurred: {e}") + # except Exception as e: + # logger.error(f"An unrelated error occurred: {e}") + + def send_register_mail(signup_email, pending_uid, pending_id, firstname, lastname): pending_member = { diff --git a/docker-compose.yml b/docker-compose.yml index 1e46992..dab9d4c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,8 @@ services: ports: - "${APP_PORT:-14700}:5000" environment: + - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} + - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} - FLASK_APP=${FLASK_APP} - FLASK_ENV=${FLASK_ENV} - DATABASE_URL=postgresql+psycopg2://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME} diff --git a/requirements.txt b/requirements.txt index fa6504e..a271ed2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -49,4 +49,8 @@ requests openai -redis \ No newline at end of file +redis + +sendgrid + +boto3 \ No newline at end of file