Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #! /usr/local/bin/python
  2.  
  3. SMTPserver = 'smtp.sina.com'
  4. sender = '<milanlanlanlan@sina.com>'
  5. destination = ['1291023320@qq.com']
  6.  
  7. USERNAME = "milanlanlanlan@sina.com"
  8. PASSWORD = "*******"
  9.  
  10. # typical values for text_subtype are plain, html, xml
  11. text_subtype = 'plain'
  12.  
  13. content="""\
  14. Test message
  15. """
  16.  
  17. subject="Sent from Python"
  18.  
  19. import sys
  20. import os
  21. import re
  22.  
  23. from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
  24. # from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
  25.  
  26. # old version
  27. # from email.MIMEText import MIMEText
  28. from email.mime.text import MIMEText
  29.  
  30. try:
  31. msg = MIMEText(content, text_subtype)
  32. msg['Subject']= subject
  33. msg['From'] = sender # some SMTP servers will do this automatically, not all
  34.  
  35. conn = SMTP(SMTPserver, 465)
  36. conn.set_debuglevel(False)
  37. conn.login(USERNAME, PASSWORD)
  38. try:
  39. conn.sendmail(sender, destination, msg.as_string())
  40. finally:
  41. conn.quit()
  42.  
  43. print "Send successfully!"
  44.  
  45. except Exception, exc:
  46. sys.exit( "mail failed; %s" % str(exc) ) # give a error message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement