Added AWS SES email
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
|
||||
"MERMS-Web" was successfully created and added to the next step.
|
||||
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
|
||||
Configure your application
|
||||
Configure your application with the settings below.
|
||||
|
||||
Server smtp.sendgrid.net
|
||||
Ports
|
||||
25, 587 (for unencrypted/TLS connections)
|
||||
465 (for SSL connections)
|
||||
Username apikey
|
||||
Password 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
|
||||
|
||||
|
||||
|
||||
Create an API key
|
||||
This allows your application to authenticate to our API and send mail. You can enable or disable additional permissions on the API keys page.
|
||||
|
||||
"Chief-Works" was successfully created and added to the next step.
|
||||
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
|
||||
Configure your application
|
||||
Configure your application with the settings below.
|
||||
|
||||
Server smtp.sendgrid.net
|
||||
Ports
|
||||
25, 587 (for unencrypted/TLS connections)
|
||||
465 (for SSL connections)
|
||||
Username apikey
|
||||
Password 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
|
||||
|
||||
|
||||
SMTP credentials
|
||||
IAM user name
|
||||
|
||||
ses-smtp-user.20260425-142515
|
||||
SMTP user name
|
||||
|
||||
AKIAZAI4GVFJOPMTPLPL
|
||||
SMTP password
|
||||
|
||||
BBawlUaS79J04F++4PvIhd2ULJT61vLOWvGNQKIPM6q+
|
||||
Hide
|
||||
|
||||
|
||||
|
||||
SMTP credentials
|
||||
IAM user name
|
||||
|
||||
ses-smtp-user.20260425-144948
|
||||
SMTP user name
|
||||
|
||||
AKIAZAI4GVFJK2G2HEHE
|
||||
SMTP password
|
||||
|
||||
BE9Lc5jMU1m58Jlfeey20IQ7OPz5jBA3q8BhMwVJjLD7
|
||||
Hide
|
||||
@@ -0,0 +1,39 @@
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from app.utils.logger import logger
|
||||
|
||||
|
||||
# @staticmethod
|
||||
def send_email_ses(to_email, subject, html_content, text_content=None):
|
||||
AWS_REGION = "us-east-1"
|
||||
FROM_EMAIL = "support@mermsemr.com" # Must be verified in SES
|
||||
|
||||
client = boto3.client(
|
||||
"ses",
|
||||
region_name=AWS_REGION,
|
||||
# Credentials pulled from env vars: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
|
||||
# or from IAM role if running on EC2/ECS
|
||||
)
|
||||
|
||||
body = {"Html": {"Charset": "UTF-8", "Data": html_content}}
|
||||
if text_content:
|
||||
body["Text"] = {"Charset": "UTF-8", "Data": text_content}
|
||||
|
||||
try:
|
||||
response = client.send_email(
|
||||
Source=FROM_EMAIL,
|
||||
Destination={"ToAddresses": [to_email]},
|
||||
Message={
|
||||
"Subject": {"Charset": "UTF-8", "Data": subject},
|
||||
"Body": body,
|
||||
},
|
||||
)
|
||||
logger.info(f"SES email sent. MessageId: {response['MessageId']}")
|
||||
return response
|
||||
|
||||
except ClientError as e:
|
||||
logger.error(f"SES ClientError: {e.response['Error']['Message']}")
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"SES send failed: {e}")
|
||||
raise
|
||||
@@ -0,0 +1,37 @@
|
||||
from app.utils.logger import logger
|
||||
from marshmallow import ValidationError
|
||||
from flask_mail import Mail, Message
|
||||
from sendgrid import SendGridAPIClient
|
||||
from sendgrid.helpers.mail import Mail
|
||||
|
||||
|
||||
@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}")
|
||||
|
||||
Reference in New Issue
Block a user