There are tons of reasons you may want to use transactionnal emails in your software.
For instance, I use it to send reports when a task is completed, or alerts when something went wrong during a process.
I used a few different solutions in the past, from setting up my own SMTP server to using Email as a Service providers. Each one came with its own issues.
I’ve been using AWS Simple Email Service for a while, and for the first time I can say this works like a charm.
Plus it’s free for 10,000 emails per month, which is a lot more than what I need.
Here is a quick recap on how I set it up with Python.
Sign up to AWS and verify your email
The Quick Start handles the very basic first steps to creating your account and sending your first email.
You’ll need to:
- Sign up to AWS SES
- Verify your email adress or your domain
- Check if everything works fine by sending an email via SES console
Once everything is in order, follow these instructions to obtain a username and password for the SMTP servers.
Send emails with Amazon SES in Python
A few different solutions are available for emails in Python. My favorite is emails, which is very simple and effective.
Install it using
pip in the command line:
You can then send emails in any Python script with only a few lines of code. To use Amazon SES with SMTP, you simply need to use port 587 and TLS authentication. The rest is quite straigt forward.
Here’s a quick example:
You can use the
emails library with any other SMTP host, as well as attach files and a lot of other features. Check the doc to know more!