How to Send mail using Simple Email Services (SES) using Amazon Web Services (AWS) by Python Script

Sathish Nadarajan
Solution Architect
September 18, 2018
Rate this article
[Total: 0    Average: 0/5]


In this article, let us see how to send emails using AWS SES. AWS is providing one-year free license. Hope that is a straight forward approach to create an AWS Subscription. Hence, not focusing on that. Let us assume that, we have a Free/Paid Subscription already available.

1. Login to the AWS Console.


2. Click on the Services menu. We can see the list of services available.


3. Click on the “Simple Email Service” under the Category “Customer Engagement” section.


4. We need to Verify the From Address and the To Addresses to send and receive email through SES. The “To” Address can be a domain or a list of email address.

5. Click on the Verify a New Email Address.







1. Login to the URL from the AWS Console.


2. Click on the “Create New Access Key”.

3. A new access key will be generated. The same can be downloaded as a CSV file as well. By Default, the CSV file name would be “rootkey.csv

4. Make a note of the Access Key and the Secret Key.

Python and AWS CLI Installation

1. On the EMR Cluster, ensure that the Python has been installed. If not, we can download and install the Python from

2. Ensure the AWS CLI also installed on the EMR Cluster. If not, by using the below command lines, we can install the AWS CLIENT and Boto3.

a. Python -m pip install awscli

b. Python -m pip install boto3

Shared Credentials File

1. We need to add the Access Key and the Secret Key which we generated few steps back to the Shared Config Credentials File.

2. The location of the Config file will be as shown in the below table.

If you’re using…Save the file as…
Linux, macOS or Unix~/.aws/credentials

3. Create a blank txt file with the name “credentials” without any extension.

4. Add the below lines of configuration values on the file.


aws_access_key_id = YOUR_AWS_ACCESS_KEY_ID

aws_secret_access_key = YOUR_AWS_SECRET_ACCESS_KEY

5. If we could not find the config file or cant able to create a file without extension, (when I try it from the Windows Server, I could not create the file), the workaround would be from the command prompt, enter the below command.

aws configure


6. Enter the Access Key, Secret Key and the Default Region When prompted.


7. Once, we register the aws Credentials on the EMR cluster from which we are planning to send email, then the below line of python script will be sending the email. The piece of code is self explanatory with the inline comments.


 #import the boto library
 #establish the connection with the access and secret keys
 conn =
 #verified Sender Mail ID
 SENDER = ''
 #verified Receiver Mail ID
 #Subject Line of the Mail
 SUBJECT = 'Mail Triggerred from SES'
 #Actual HTML Content
 CONTENT='<html><body><table><tr>First Row</tr><tr>Second Row</tr></table></body></html>'
 #The HTML content is framed and kept in the TXT file.  The below lines should be implemented to read the actual file content
 #file=open("/home/Test.txt", "r")
 #read the content from the file
 #Calling the Send Mail function with proper parameters




Happy Coding,

Sathish Nadarajan.

Category : AWS, SES

Author Info

Sathish Nadarajan
Solution Architect
Rate this article
[Total: 0    Average: 0/5]
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business more

Leave a comment