How to send an email with Python?
Sending emails with python is something that I struggled with because I could not find the right tools and examples for me to get started. While starting to send emails with python, I thought that would be easy but no, it was not. I decided to make this article to tell you the easiest way to send a simple email with python3.
I found that using smtplib and the email libraries in python was the easiest way I could find.
Here is the code:
Let’s talk about the code
We first import the required modules, then we assign the values required to variables, and then we set the From, To, Subject, and message of the email. After that, we will use the try statement to attempt to send the email and login to the email server. Then send an email from the login user to the recipient of the email. If the login or email sending encounters an error, it will print the error to the console, and then finally it will quit the server no matter if passed or failed.