Send an email with Amazon SES + Python

What is Amazon SES?

--Email platform provided by Amazon --Pay-as-you-go system

procedure

--Region selection --Register an email address for sending --Releasing transmission restrictions --Implementation of email sending process

Region selection

Amazon SES currently supports the following regions: スクリーンショット 2020-05-14 14.32.48.png

Register an email address for sending

Amazon SES requires you to verify and register your sending email address. (You cannot use an unverified email address.)

--Enter the email address you want to register for sending from the [Verify a New Adress] button on the [Email Addresses] tab of SES. スクリーンショット 2020-05-14 14.26.06.png

--You will receive an authentication email, so complete the authentication from the URL of the email.

Remove transmission restrictions

If you do nothing, you can send emails only to the authenticated email address and the number of emails sent is limited, so you need to remove the restriction.

--Click the Request a Sending Limit Increase button on the SES Sending Statistics tab --You will be taken to the Support Center page, so enter the required information. スクリーンショット 2020-05-14 14.44.43.png --Application

Implementation of email transmission

import boto3

def main():
  try:
    client = boto3.client(
      'ses',
      aws_access_key_id={AWS_ACCESS_KEY_ID},
      aws_secret_access_key={AWS_SECRET_ACCESS_KEY},
      region_name='us-east-1' #Region where the sending email address is registered
    )

    client.send_email(
      Destination={
        'ToAddresses': ['[email protected]', '[email protected]'],
        'BccAddresses': ['[email protected]']
      },
      Message={
        'Body': {
          'Text': {
            'Data': 'the content of the email',
            'Charset': 'utf-8'
          }
        },
        'Subject': {
          'Data': 'subject',
          'Charset': 'utf-8'
        }
      },
      Source='[email protected]', #Registered e-mail address
      ConfigurationSetName='The name you want to display as the email sender'
    )
  except ClientError as e:
    print(e.response['Error']['Message'])
  else:
    print(response['MessageId'])

reference

Amazon SES Developer Guide

Recommended Posts

Send an email with Amazon SES + Python
[Python] Send an email with outlook
Send email with Python
Send Japanese email with Python3
Send an email to Spushi's address with python
Send an email with Excel attached in Python
[boto3] Send an email using SES
[Automation] Send Outlook email with Python
Note: Send an email with Django
Automatically send emails with Amazon SES
Send email via gmail with Python 3.4.3.
[Python] Send email
[Python] Send email
[Python] Send an email from gmail with two-step verification set
HTML email with image to send with python
I tried sending an email with python.
Send email with Django
Validate E-Mail with Python
I tried sending an email with SendGrid + Python
What to do if you couldn't send an email to Yahoo with Python.
Send an email to a specific email address with python without SMTP settings
Send email with SES in Python and short message with SMS on SNS
Creating an egg with python
Send email in Python (Outlook)
To automatically send an email with an attachment using the Gmail API in Python
Send using Python with Gmail
If you can't send an email with python smtplib and have trouble, command line
Create an Excel file with Python3
I sent an SMS with Python
Easy email sending with haste python3
Draw an illustration with Python + OpenCV
Send multipart / form-data with python requests
Send image with python, save with php
[Python] Building an environment with Anaconda [Mac]
Building a Python3 environment with Amazon Linux2
Uncle SES modernizes VBA app with Python
Note when creating an environment with python
Send email to multiple recipients in Python (Python 3)
Quickly create an excel file with Python #python
[Python] Quickly create an API with Flask
Scraping from an authenticated site with python
Create an English word app with python
Join an online judge with Python 3.x
Let's develop an investment algorithm with Python 1
Python 3.6 email library
FizzBuzz with Python3
Send a message to LINE with Python (LINE Notify)
Scraping with Python
Statistics with python
Create an app that guesses students with python
[Python] Make a game with Pyxel-Use an editor-
Scraping with Python
Python with Go
Building an Anaconda environment for Python with pyenv
Let's write FizzBuzz with an error: Python Version
I want to send Gmail with Python, but I can't because of an error
[Python] Clustering with an infinitely mixed Gaussian model
Twilio with Python
How to crop an image with Python + OpenCV
Integrate with Python
Play with 2016-Python