Guest User

Untitled

a guest
Aug 19th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. def send_email(to_email, subject, body): #to send an email
  2. gmail_user = "demosal023@gmail.com"
  3. gmail_password = "SAL123xyz!"
  4.  
  5. sent_from = gmail_user
  6. to = to_email
  7. sub = subject
  8.  
  9.  
  10. email_text = """\
  11. From: %s
  12. To: %s
  13. Subject: %s
  14.  
  15. %s
  16. """ % (sent_from,"SAL", sub, body)
  17.  
  18. try:
  19. server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  20. server.ehlo()
  21. server.login(gmail_user, gmail_password)
  22. server.sendmail(sent_from, to, email_text)
  23. server.close()
  24.  
  25. print ("Email sent!")
  26. except:
  27. print ("Something went wrong...")
Add Comment
Please, Sign In to add comment