sendmail.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. #coding: utf-8
  3. # sendEmail title content
  4. import sys
  5. import smtplib
  6. from email.mime.text import MIMEText
  7. from email.header import Header
  8. sender = 'xxxxx'
  9. receiver = '489456155@qq.com'
  10. smtpserver = 'smtp.exmail.qq.com'
  11. username = sender
  12. password = 'xxxxx'
  13. def send_mail(title, content):
  14. try:
  15. msg = MIMEText(content,'plain','utf-8')
  16. if not isinstance(title,unicode):
  17. title = unicode(title, 'utf-8')
  18. msg['Subject'] = title
  19. msg['From'] = sender
  20. msg['To'] = receiver
  21. msg["Accept-Language"]="zh-CN"
  22. msg["Accept-Charset"]="ISO-8859-1,utf-8"
  23. msg['CC'] = 'zhaoashen@gmail.com;zhaoas@uubee.com;apple_developer@uubee;'
  24. smtp = smtplib.SMTP_SSL(smtpserver,465)
  25. smtp.login(username, password)
  26. smtp.sendmail(sender, receiver, msg.as_string())
  27. smtp.quit()
  28. print "邮件发送成功!"
  29. return True
  30. except Exception, e:
  31. print str(e)
  32. print "邮件发送失败!"
  33. return False