Guest User

Untitled

a guest
Dec 5th, 2017
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. def send_email(user, pwd, recipient, subject, body):
  2. import smtplib
  3.  
  4. gmail_user = 'olegserdia@gmail.com'
  5. gmail_pwd = 'MyEmailPassword'
  6. FROM = 'olegserdia@gmail.com'
  7. TO = 'olegserdia@gmail.com'
  8. SUBJECT = 'Test'
  9. TEXT = 'Hello, this is test email'
  10.  
  11. # Prepare actual message
  12. message = """From: %snTo: %snSubject: %snn%s
  13. """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  14. try:
  15. server = smtplib.SMTP("smtp.gmail.com", 587)
  16. server.ehlo()
  17. server.starttls()
  18. server.login(gmail_user, gmail_pwd)
  19. server.sendmail(FROM, TO, message)
  20. server.close()
  21. print ('successfully sent the mail')
  22. except:
  23. print ("failed to send mail")
Add Comment
Please, Sign In to add comment