Amazon Simple Email Service
Developer Guide

Send an Email Using the AWS SDK for Python (Boto)

This topic shows how to use the AWS SDK for Python (Boto) to send an email through Amazon SES.


In this tutorial, you send an email to yourself so that you can check to see if you received it. For further experimentation or load testing, use the Amazon SES mailbox simulator. Emails that you send to the mailbox simulator do not count toward your sending quota or your bounce and complaint rates. For more information, see Testing Email Sending in Amazon SES.


Before you begin, perform the following tasks:

  • Verify your email address with Amazon SES—Before you can send an email with Amazon SES, you must verify that you own the sender's email address. If your account is still in the Amazon SES sandbox, you must also verify the recipient email address. The easiest way to verify email addresses is by using the Amazon SES console. For more information, see Verifying Email Addresses in Amazon SES.

  • Get your AWS credentials—You need an AWS access key ID and AWS secret access key to access Amazon SES using an SDK. You can find your credentials by using the Security Credentials page of the AWS Management Console. For more information about credentials, see Using Credentials With Amazon SES.

  • Install Python—Python is available at The code in this tutorial was tested using Python 2.7.6 and Python 3.6.1. After you install Python, add the path to Python in your environment variables so that you can run Python from any command prompt.

  • Install the AWS SDK for Python (Boto)—For download and installation instructions, see the AWS SDK for Python (Boto) documentation. The sample code in this tutorial was tested using version 1.4.4 of the SDK for Python.

  • Create a shared credentials file—For the sample code in this section to function properly, you must create a shared credentials file. For more information, see Create a Shared Credentials File.


The following procedure shows how to send an email through Amazon SES using the SDK for Python.

To send an email through Amazon SES using the SDK for Python

  1. In a text editor, create a file named Paste the following code into the file:

    import boto3 from botocore.exceptions import ClientError # Replace with your "From" address. # This address must be verified with Amazon SES. SENDER = "Sender Name <>" # Replace with a "To" address. If your account # is still in the sandbox, this address must be verified. RECIPIENT = "" # Specify a configuration set. If you do not want to use a configuration # set, comment the following variable, and the # ConfigurationSetName=CONFIGURATION_SET argument below. CONFIGURATION_SET = "ConfigSet" # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES. AWS_REGION = "us-west-2" # The subject line for the email. SUBJECT = "Amazon SES Test (SDK for Python)" # The email body for recipients with non-HTML email clients. BODY_TEXT = ("Amazon SES Test (Python)\r\n" "This email was sent with Amazon SES using the " "AWS SDK for Python (Boto)." ) # The HTML body of the email. BODY_HTML = """<html> <head></head> <body> <h1>Amazon SES Test (SDK for Python)</h1> <p>This email was sent with <a href=''>Amazon SES</a> using the <a href=''> AWS SDK for Python (Boto)</a>.</p> </body> </html> """ # The character encoding for the email. CHARSET = "UTF-8" # Create a new SES resource and specify a region. client = boto3.client('ses',region_name=AWS_REGION) # Try to send the email. try: #Provide the contents of the email. response = client.send_email( Destination={ 'ToAddresses': [ RECIPIENT, ], }, Message={ 'Body': { 'Html': { 'Charset': CHARSET, 'Data': BODY_HTML, }, 'Text': { 'Charset': CHARSET, 'Data': BODY_TEXT, }, }, 'Subject': { 'Charset': CHARSET, 'Data': SUBJECT, }, }, Source=SENDER, # If you are not using a configuration set, comment or delete the # following line ConfigurationSetName=CONFIGURATION_SET, ) # Display an error if something goes wrong. except ClientError as e: print(e.response['Error']['Message']) else: print("Email sent! Message ID:"), print(response['MessageId'])
  2. In, replace the following with your own values:

    •—Replace with an email address that you have verified with Amazon SES. For more information, see Verifying Identities. Email addresses in Amazon SES are case-sensitive. Make sure that the address you enter is exactly the same as the one you verified.

    •—Replace with the address of the recipient. If your account is still in the sandbox, you must verify this address before you use it. For more information, see Moving Out of the Amazon SES Sandbox. Make sure that the address you enter is exactly the same as the one you verified.

    • (Optional) us-west-2—If you want to use Amazon SES in a region other than US West (Oregon), replace this with the region you want to use. For a list of regions in which Amazon SES is available, see Regions and Amazon SES.

  3. Save

  4. To run the program, open a command prompt in the same directory as, and then type python

  5. Review the output. If the email was successfully sent, the console displays "Email sent!" Otherwise, it displays an error message.

  6. Sign in to the email client of the recipient address. You will find the message that you sent.

On this page: