Amazon Simple Email Service
Developer Guide

Verify Multiple Email Addresses

If you are migrating to Amazon SES from another email-sending solution, you may already have a long list of email addresses that you want to use to send email. The Python script in this example accepts a JSON-formatted list of email addresses as an input. The following example shows the structure of the input file:

[ { "email":"" }, { "email":"" }, { "email":"" } ]

The following script reads the input file and attempts to validate all of the email addresses contained in the file. This code example assumes that you have installed the AWS SDK for Python (Boto), and that you have created a shared credentials file. For more information about creating a shared credentials file, see Create a Shared Credentials File.

import json #Python standard library import boto3 #sudo pip install boto3 from botocore.exceptions import ClientError # The full path to the file that contains the identities to be verified. # The input file must be JSON-formatted. See # # for a sample input file. FILE_INPUT = '/path/to/identities.json' # If necessary, replace us-west-2 with the AWS Region you're using for Amazon SES. AWS_REGION = "us-west-2" # Create a new SES resource specify a region. client = boto3.client('ses',region_name=AWS_REGION) # Read the file that contains the identities to be verified. with open(FILE_INPUT) as data_file: data = json.load(data_file) # Iterate through the array from the input file. Each time an object named # 'email' is found, run the verify_email_identity operation against the value # of that object. for i in data: try: response = client.verify_email_identity( EmailAddress=i['email'] ) # Display an error if something goes wrong. except ClientError as e: print(e.response['Error']['Message']) # Otherwise, show the request ID of the verification message. else: print('Verification email sent to ' + i['email'] + '. Request ID: ' + response['ResponseMetadata']['RequestId'])