In this article we are going to explain how to send an e-mail through a simple python script. This software results to be very useful if you are using linux based system, because you can run it directly from command-line

Python

Python is one of the most popular coding languages. The syntax is very clean and the multiplatform-support is included. Nowadays a lot of software are developed thorough it.

SMTP

In this article we are going to explain how to use the SMTP client session object to send e-mail to any SMTP or ESMTP listener machine on the internet. SMTP stands for Simple Mail Transfer Protocol. To use this protocol we have to include the smtplib module.

Script

Here we go, first to all we need to import smtp in this way

image

Then let’s set up your email server. We have used our mail server: mail.cmprogrammers.com. Just insert your one. In case authentication is required you have to add username and password to log in.

image

At this point we have to set up the sender, the receiver(s) and the text of the message we’d like to send.

image

If you want to add more receivers just follow this syntax:

receivers = [‘user1@mail.com', ‘user2@mail.com', 'user3@mail.com', ‘userN@mail.com']

Finally we can send our email

image

Code

You can download the complete script from here. Remember to configure it following your needs.

image

Have fun!