How to send emails with Python and Mailgun
Remember to get the Insomnia files for this section or for all sections here!
To send e-mails using Python, we are going to use Mailgun, a third party service which actually delivers the messages.
You could use your own personal account and the built-in email
and smtp
libraries, but most personal e-mail providers will limit how many e-mails you can send per day. Plus, you won't get analytics and a host of other features that you can get with an email service like Mailgun.
There are two ways to use the Mailgun service: via SMTP or via their API. I'll show you how to use the API since it's a bit easier and has the same functionality.
Sending an e-mail with Mailgun is just a matter of sending a request to their API. To do this, we'll use the requests
library:
pip install requests
Remember to add it to your requirements.txt
as well:
requests