环境:python3 ,IDE : pycharm

非常奇怪的是,用163发送邮件,如果电脑连校园网发送,会被当成垃圾邮件拒绝

如果用手机开热点就可以正常发送

代码如下

 1 #!/usr/bin/python
 2 # -*- coding: utf-8 -*-
 3 import time
 4 import smtplib
 5 from email.mime.text import MIMEText
 6 from email.mime.multipart import MIMEMultipart
 7 
 8 # 第三方 SMTP 服务
 9 mail_host = ""      # SMTP服务器a
10 mail_user = ""                  # 用户名
11 mail_pass = ""               # 授权密码,非登录密码
12 
13 sender = ''    # 发件人邮箱(最好写全, 不然会失败)
14 receivers = ['']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
15 
16 title = '163邮件测试'  # 邮件主题
17 content = '我用Python'
18 
19 def sendEmail():
20     message = MIMEMultipart()
21     message.attach(MIMEText(content, 'plain', 'utf-8'))
22     message['From'] = "{}".format(sender)  # 发件人
23     message['To'] = ",".join(receivers)  # 收件人
24     message['Subject'] = title  # 邮件主题
25 
26     try:
27         smtpObj = smtplib.SMTP_SSL(mail_host, 465)  # 启用SSL发信, 端口一般是465
28         smtpObj.login(mail_user, mail_pass)  # 登录验证
29         smtpObj.sendmail(sender, receivers, message.as_string())  # 发送
30         print("mail has been send successfully.")
31     except smtplib.SMTPException as e:
32         print(e)
33 
34 if __name__ == '__main__':
35     print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
36     sendEmail()
View Code

相关文章:

  • 2019-09-15
  • 2021-08-31
  • 2021-11-03
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案