Sending emails with AWS Python SDK


Houston we have a problem. Not Houston. I’m the one with the problem. I need to send emails to my list of users but I know that some of these users were spam users. I need a way to send emails and also remove invalid emails from my system.

In the past I have used AWS .NET SDK to send emails and also track bounces and complaints. But I want to challenge myself so I want to play with the Python SDK. In this post, I want to share how to send emails using the AWS Python SDK.

Install the python SDK by following these instructions. Make sure to setup a profile that has permissions to send emails. In this example, I’m using a profile name “python-scripts” that has permissions to send ses emails. Make sure you set this name based on your setup.

After installing boto3, we are ready to create a class responsible to send emails. Take a look at EmailController.py below:


Now let’s create a class that uses EmailController.py. Take a look at EmailRunner.py.

I like to keep things simple. I have a csv file with all the email addresses. Each line in the csv file has an email address. Next, my class reads each line and sends an email. If there are any errors while sending the emails, I’ll use another csv file to keep track of these errors.

If we were able to send emails successfully, we will receive a valid response with status of 200.

That’s all for today. In a future post, I’m going to show you how to setup sns notifications for bounces and complaints. Have a nice day!