Guest User

Untitled

a guest
Dec 10th, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import smtplib
  2.  
  3. gmail_user = "username@gmail.com"
  4. gmail_password = "******"
  5.  
  6. sent_from = gmail_user
  7. file = open("email_list.txt", "r")
  8. to = file.readlines()
  9. subject = "SUBJECT OF E-MAIL"
  10. body = "BODY OF E-MAIL"
  11.  
  12. email_text = """
  13. From: %s
  14. To: %s
  15. Subject: %s
  16.  
  17. %s
  18. """ % (sent_from, ", ".join(to), subject, body)
  19.  
  20. try:
  21. server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  22. server.ehlo()
  23. server.login(gmail_user, gmail_password)
  24. server.sendmail(sent_from, to, email_text)
  25. server.close()
  26.  
  27. print("Email sent!")
  28. except:
  29. print("Error!")
Add Comment
Please, Sign In to add comment