January 2019
Beginner
318 pages
8h 23m
English
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 smtplibfrom email.mime.text import MIMETextimport getpasshost_name = 'smtp.gmail.com'port = 465u_name = 'username/emailid'password = getpass.getpass()sender = 'sender_name'receivers = ['receiver1_email_address', 'receiver2_email_address']text = ...
Read now
Unlock full access