Added AWS SES email
This commit is contained in:
+106
-25
@@ -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="<strong>Hello from AWS SES</strong>"
|
||||
)
|
||||
# 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='<strong>and easy to do anywhere, even with Python</strong>'
|
||||
)
|
||||
|
||||
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 = {
|
||||
|
||||
Reference in New Issue
Block a user