Files
2026-04-26 01:11:30 -04:00

38 lines
1.2 KiB
Python

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 send_email_sendgrid():
# 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}")