Guest User

Untitled

a guest
May 20th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import smtplib
  2. from email.mime.multipart import MIMEMultipart
  3. from email.mime.text import MIMEText
  4. from email.mime.base import MIMEBase
  5. from email import encoders
  6.  
  7. toddr_list = ["[email protected]"]
  8. fromaddr = "[email protected]"
  9. for i in toddr_list:
  10.     toaddr = i
  11.        
  12.     # instance of MIMEMultipart
  13.     msg = MIMEMultipart()
  14.      
  15.     # storing the senders email address  
  16.     msg['From'] = fromaddr
  17.      
  18.     # storing the receivers email address  
  19.     msg['To'] = toaddr
  20.      
  21.     # storing the subject  
  22.     msg['Subject'] = "Subject  "
  23.      
  24.     # string to store the body of the mail
  25.     body = "Content  "
  26.     # attach the body with the msg instance
  27.     msg.attach(MIMEText(body, 'plain'))      
  28.      
  29.     # creates SMTP session
  30.     s = smtplib.SMTP('smtp.gmail.com', 587)
  31.      
  32.     # start TLS for security
  33.     s.starttls()
  34.      
  35.     # Authentication
  36.     s.login(fromaddr, "password")
  37.      
  38.     # Converts the Multipart msg into a string
  39.     text = msg.as_string()
  40.      
  41.     # sending the mail
  42.     s.sendmail(fromaddr, toaddr, text)
  43.      
  44.     # terminating the session
  45.     s.quit()
Add Comment
Please, Sign In to add comment