Python – Send email to a list of emails from a spreadsheet
Nowadays working with Google forms is quite popular. It is used to mass gather information easily. Email addresses are one of the most common piece of information asked. It is stored in a spreadsheet. In this article we shall see how to send an email to all the email addresses present in a spreadsheet. Prerequisite knowledge:
- Loading Excel spreadsheet as pandas DataFrame
- Send mail from your Gmail account using Python
Procedure:
- Step 1: Read the spreadsheet using the pandas library. The structure of the spreadsheet used here is :
- Step 2: Establish connection with your gmail account using smtplib library.
- Step 3: Extract the names and email addresses from the spreadsheet.
- Step 4: Run a loop and for every record send an email.
- Step 5: Close the smtp server.
The Python implementation is:
Python3
import pandas as pd
import smtplib
your_email = "XYZ@gmail.com"
your_password = "XYZ"
server = smtplib.SMTP_SSL( 'smtp.gmail.com' , 465 )
server.ehlo()
server.login(your_email, your_password)
email_list = pd.read_excel( 'C:/Users/user/Desktop/gfg.xlsx' )
names = email_list[ 'NAME' ]
emails = email_list[ 'EMAIL' ]
for i in range ( len (emails)):
name = names[i]
email = emails[i]
message = "Hello " + name
server.sendmail(your_email, [email], message)
server.close()
|
Last Updated :
06 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...