A simple script to send email by SMTP in Python

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



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム