In this section, we are going to learn about sending an email from Gmail through a Python script. To do this, Python has a module named smtplib. The smtplib module in Python provides SMTP client session object that is used to send an email to any internet machine with SMTP listener.
We are going to look at an example. In this example, we will send an email containing a simple text from Gmail to the recipients.
Create a send_email.py script and write the following content in it:
import smtplib
from email.mime.text import MIMEText
import getpass
host_name = 'smtp.gmail.com'
port = 465
u_name = 'username/emailid'
password = getpass.getpass()
sender = 'sender_name'
receivers = ['receiver1_email_address', 'receiver2_email_address']
text = MIMEText('Test mail')
text['Subject'] = 'Test'
text['From...