Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import smtplib
  2.  
  3. def send_email(recipient, subject, body):
  4. gmail_user = 'rafal.sikora.pl@gmail.com'
  5. gmail_password = 'haslo'
  6.  
  7. FROM = gmail_user
  8. TO = recipient if isinstance(recipient, list) else [recipient]
  9. SUBJECT = subject
  10. TEXT = body
  11.  
  12. # Prepare actual message
  13. message = """From: %s\nTo: %s\nSubject: %s\n\n%s
  14. """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  15. # SMTP_SSL Example
  16. server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
  17. server_ssl.ehlo() # optional, called by login()
  18. server_ssl.login(gmail_user, gmail_password)
  19. server_ssl.sendmail(FROM, TO, message)
  20. #server_ssl.quit()
  21. server_ssl.close()
  22. print ('successfully sent the mail')
  23. print ("failed to send mail")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement