Guest User

Untitled

a guest
May 2nd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import smtplib
  2. import sys
  3. import email.mime.text
  4. mail_username='gmailUser@gmail.com'
  5. mail_password='password'
  6. from_addr = mail_username
  7. to_addrs=('gmailUser@gmail.com')
  8.  
  9. HOST = 'smtp.gmail.com'
  10. PORT = 25
  11.  
  12. # Create SMTP Object
  13. smtp = smtplib.SMTP()
  14. print 'connecting ...'
  15.  
  16. # show the debug log
  17. smtp.set_debuglevel(1)
  18.  
  19. # connet
  20. try:
  21. print smtp.connect(HOST,PORT)
  22. except:
  23. print 'CONNECT ERROR ****'
  24. # gmail uses ssl
  25. smtp.starttls()
  26. # login with username & password
  27. try:
  28. print 'loginning ...'
  29. smtp.login(mail_username,mail_password)
  30. except:
  31. print 'LOGIN ERROR ****'
  32. # fill content with MIMEText's object
  33. msg = email.mime.text.MIMEText('Hi ,All')
  34. msg['From'] = from_addr
  35. msg['To'] = ';'.join(to_addrs)
  36. msg['Subject']='this is test msg'
  37. print msg.as_string()
  38. smtp.sendmail(from_addr,to_addrs,msg.as_string())
  39. smtp.quit()
Add Comment
Please, Sign In to add comment