· 7 years ago · Aug 26, 2018, 01:58 PM
1#from email.MIMEMultipart import MIMEMultipart # Python 2.x
2#from email.MIMEText import MIMEText # Python 2.x
3from email.mime.multipart import MIMEMultipart
4from email.mime.text import MIMEText
5import smtplib
6
7fromAddress = "@gmail.com" # TODO: Enter the gmail address of the sender
8toAddress = "@email.com" # TODO: Enter the email address of the receiver
9subject = "" # TODO: Enter Subject of the email
10msg = MIMEMultipart()
11msg['From'] = fromAddress
12msg['To'] = toAddress
13msg['Subject'] = subject
14body = "" # TODO: Enter Body of the email
15msg.attach(MIMEText(body, 'plain'))
16
17server = smtplib.SMTP('smtp.gmail.com', 587) # This is if the sender's email is gmail
18server.ehlo()
19server.starttls()
20server.ehlo()
21server.login(fromAddress, "password") # TODO: Enter password
22text = msg.as_string()
23server.sendmail(fromAddress, toAddress, text)
24server.quit()