[PYTHON] [boto3] Send an email using SES

With boto3, you can send emails from Python via SES.

        client = boto3.client('ses')
        response = client.send_email(
            Source='[email protected]',
            Destination={
                'ToAddresses': [
                    '[email protected]',
                ],
                'CcAddresses': [
                    '[email protected]',
                ],
                'BccAddresses': [
                    '[email protected]',
                ]
            },
            Message={
                'Subject': {
                    'Data': 'SES Mail by Python',
                    'Charset': 'UTF-8'
                },
                'Body': {
                    'Text': {
                        'Data': 'This is text mail',
                        'Charset': 'UTF-8'
                    },
                    'Html': {
                        'Data': '<h1>This is Html Mail</h1>',
                        'Charset': 'UTF-8'
                    }
                }
            },
            ReplyToAddresses=[
                '[email protected]',
            ]
        )

Execute

When executed, an email will be sent as shown below.

スクリーンショット 2017-01-12 15.08.10.png

Tips

HTML email and text email

It seems that Message ['Body'] ['Text'] is not displayed when there is Message ['Body'] ['Html'] and the client can see HTML mail.

About the address

Use the address you put in Source that has been authenticated by your SES account.

About authority

The permissions required to run are ses: SendEmail. Create a role like the one below and assign it to a Lambda or IAM user.

{
  "Version": "2012-10-17",
  "Statement": [{
      "Action": [
        "ses:SendEmail"
      ],
      "Resource": [
        "arn:aws:ses:*"
      ],
      "Effect": "Allow"
  }]
}

Other

It seems that you can also process bounces, so if you are interested, please see below. http://boto3.readthedocs.io/en/latest/reference/services/ses.html#SES.Client.send_email

Recommended Posts

[boto3] Send an email using SES
Send an email with Amazon SES + Python
Send email using Python's smtplib
Note: Send an email with Django
[Python] Send an email with outlook
[Python] Send email
[Python] Send email
Send an email to Spushi's address with python
Send an email with Excel attached in Python
To automatically send an email with an attachment using the Gmail API in Python
Send email with Django
Send email with Python
I can't send emails from Lambda in a VPC with Boto3 using a VPC endpoint for SES
[Python] Send an email from gmail with two-step verification set
I tried sending an email from Amazon SES with Python
Code to send an email based on the Excel email list
Send Japanese email with Python3
Send email in Python (Outlook)
Send using Python with Gmail
When you want to send an object with requests using flask