Emails
Emails are important to communicate with your users. We will not set up an email list management tool here, these will be transactional emails. For that we will go back to AWS of course - SES (Simple Email Service) is here to help!
Setting up SES
For sending emails you will need a domain. If you don’t have one yet, buy one directly in AWS or just “transfer” the bought domain to Route53 (The DNS managment service by AWS) using nameservers. For example if you got your domain from GoDaddy, follow this video, the process is the same with other providers.
Once our domain is added to Route53, we can use it to create and validate an identity in SES itself.
This can either be single email adress (a@test.com
) or the domain itself (test.com
) which covers all the possible adresses.
Choose an approach and follow the first 90 seconds of this video.
Sending Emails with Python
SES offers two ways of sending emails:
- through the SMTP interface (Simple Mail Transfer Protocol, just imagine this as the raw request approach)
- using the Python SDK
For simplicity we will use the SDK, make sure you have followed the database chapter and configured the credentials.
Now open mail.py
, you will see that we can send both text and HTML emails. You will have to create HTML files
and pass them to the function.
Do not forget to fill the “FROM_EMAIL” key to .env
, it has to match the identity you created.
Receiving emails
The setup we have is for sending emails only. There are ways to do so programmatically or with an inbox, but they won’t be covered in here.
Production access
If you now try to send an email to a different domain, it will fail. The reason is, that SES requires a manual check, before they allow you to send emails. This is to avoid malicious activity. For requesting access follow this comprehensive video.