A simple script to send email by SMTP in Python
- 2022年4月26日
- 技術情報
Today, I would like to share about sending emails by SMTP with a simple python script. Let’s take a look.
To send smpt emails, we will need just one library smtplib that is a built-in python lib. Here is the code.

There are just simple 6 steps.
1. Connect to a SMTP server [line 3]
2. Sending the SMTP ‘Hello’ Message [line 4]
3. Starting TLS Encryption [line 5]
4. Logging in to the SMTP server [line 7]
5. Sending an Email [line 8]
6. Disconnecting from the SMTP server [line 11]
Note: To send with gmail SMTP, you will need to turn on ‘Less secure app access’ in your gmail account settings.
This is all for now. Hope you enjoy and can expand to further uses based on that.
By Asahi
waithaw at 2022年04月26日 10:00:00