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