Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (31 sloc) 1.24 KB
#!python3 is a simple script for sending emails using smtplib
#The idea is to assign a web-scraped file to the DATA_FILE constant.
#The data in the file is then read in and sent as the body of the email.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email_list import EMAILS
DATA_FILE = 'scraped_data_file'
from_addr = ''
to_addr = '' #Or any generic email you want all recipients to see
bcc = EMAILS
msg = MIMEMultipart()
msg['From'] = from_addr
msg['To'] = to_addr
msg['Subject'] = 'Subject Line'
with open(DATA_FILE) as f:
body =
msg.attach(MIMEText(body, 'plain'))
smtp_server = smtplib.SMTP('', 587) #Specify Gmail Mail server
smtp_server.ehlo() #Send mandatory 'hello' message to SMTP server
smtp_server.starttls() #Start TLS Encryption as we're not using SSL.
#Login to gmail: Account | Password
smtp_server.login(' ', ' GMAIL APPLICATION ID ')
text = msg.as_string()
#Compile email list: From, To, Email body
smtp_server.sendmail(from_addr, [to_addr] + bcc, text)
#Close connection to SMTP server
#Test Message to verify all passes
print('Email sent successfully')
You can’t perform that action at this time.