Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.mime.base import MIMEBase
- from email import encoders
- fromaddr = "[email protected]"
- for i in toddr_list:
- toaddr = i
- # instance of MIMEMultipart
- msg = MIMEMultipart()
- # storing the senders email address
- msg['From'] = fromaddr
- # storing the receivers email address
- msg['To'] = toaddr
- # storing the subject
- msg['Subject'] = "Subject "
- # string to store the body of the mail
- body = "Content "
- # attach the body with the msg instance
- msg.attach(MIMEText(body, 'plain'))
- # creates SMTP session
- s = smtplib.SMTP('smtp.gmail.com', 587)
- # start TLS for security
- s.starttls()
- # Authentication
- s.login(fromaddr, "password")
- # Converts the Multipart msg into a string
- text = msg.as_string()
- # sending the mail
- s.sendmail(fromaddr, toaddr, text)
- # terminating the session
- s.quit()
Add Comment
Please, Sign In to add comment