smtp_config.py 733 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. import smtplib
  4. from email.mime.text import MIMEText
  5. from email.header import Header
  6. #邮件发送函数
  7. def send_mail(message):
  8. # 第三方 SMTP 服务
  9. mail_host = "mail.xxx.com" # 设置服务器
  10. mail_user = "xxx" # 用户名
  11. mail_pass = "xxx" # 口令
  12. sender = 'xxx@qq.com'
  13. receivers = ['xxx@qq.com'] # 接收邮件
  14. try:
  15. smtpObj = smtplib.SMTP()
  16. smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号
  17. smtpObj.login(mail_user, mail_pass)
  18. smtpObj.sendmail(sender, receivers, message.as_string())
  19. print ("邮件发送成功")
  20. except smtplib.SMTPException:
  21. print ("Error: 无法发送邮件")
  22. return