Advertisement
Guest User

Untitled

a guest
Sep 16th, 2017
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf8 -*-
  3.  
  4. def send_mail(recipient, subject, message):
  5.  
  6. import smtplib
  7. from email.MIMEMultipart import MIMEMultipart
  8. from email.MIMEText import MIMEText
  9.  
  10. print 'Sending to %s' % recipient
  11. print 'Message text : \n%s' % message
  12.  
  13.  
  14. gmailUser = 'user@gmail.com'
  15. gmailPassword = 'password'
  16.  
  17. msg = MIMEMultipart()
  18. msg['From'] = gmailUser
  19. msg['To'] = recipient
  20. msg['Subject'] = subject
  21. msg['MIME-Version'] = "1.0"
  22. msg['Content-Type'] = "text/html; charset=utf-8"
  23. msg['Content-Transfer-Encoding'] = "quoted-printable"
  24. msg.attach(MIMEText(message, _charset='utf-8'))
  25.  
  26. mailServer = smtplib.SMTP('smtp.gmail.com', 587)
  27. mailServer.ehlo()
  28. mailServer.starttls()
  29. mailServer.ehlo()
  30. mailServer.login(gmailUser, gmailPassword)
  31. mailServer.sendmail(gmailUser, recipient, msg.as_string())
  32. mailServer.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement