Send Email with AWS SES

Using AWS SES (Simple Email Service)

Init / Imports needed

import boto3
from botocore.exceptions import ClientError

ses = boto3.client('ses')

Verify Email

def verify_email(email: str):
    response = ses.verify_email_identity(EmailAddress=email)
    print(response.text)
    return response

List Verified Emails

def list_subscribers():
    response = ses.list_identities(
        IdentityType="EmailAddress"
    )
    return response

Delete Verified Email

def delete_subscriber(email):
    response = ses.delete_identity(
        Identity=email
    )
    return response

Send Email

def send_update(email: str):
    CHARSET = "UTF-8"
    data = email_body()
    try:
        response = ses.send_email(
            Destination={
                'ToAddresses': [email]
            },
            Message={
                'Body': {
                    'Html': {
                        'Charset': CHARSET,
                        'Data': data
                    },
                    'Text': {
                        'Charset': CHARSET,
                        'Data': BODY_TEXT
                    }
                },
                'Subject': {
                    'Charset': CHARSET,
                    'Data': SUBJECT
                }
            },
            Source=SENDER)
        return {"status": 200, "message": "Email sent"}
    except ClientError as e:
        print(e.response['Error']['Message'])
    else:
        print("Email sent. Message ID:"),
        print(response['MessageId'])