Sending emails
Emails are the most widespread communication tool nowadays, if you're on the internet, it's pretty much granted you have an email address and they are now highly integrated in smartphones too, so are accessible on the go.
For all those reasons, emails are the preferred tools for sending notifications to users, reports of completion, and results of long-running processes.
Sending emails requires some machinery and both the SMTP and MIME protocols are quite articulated if you want to support them by yourself.
Luckily, the Python standard library comes with built-in support for both and we can rely on the smtplib
module to interact with the SMTP server to send our email and on email
package to actually create the content of the email and tackle all the special formats and encoding required.
How to do it...
Sending an email is a three-step process:
- Contact the SMTP server and authenticate to it
- Prepare the email itself
- Provide the email to the SMTP server
All three phases are covered in...