一、报错信息
使用SMTP发送邮件遇到以下报错(个人邮箱):
554, b'DT:SPM 163 smtp10,DsCowACXeOtmjRRdsY8aCw--.21947S2 1561628007,please see http://mail.163.com/help/help_spam_16.htm?ip=36.110.94.251&hostid=smtp10&time=1561628007'
二、排查原因
1、检查163邮箱是否设置授权码,授权码对不对。不对会报错:535, b'Error: authentication failed'
注:python3中利用163发邮件里填的账号密码不是邮箱的登录密码,而是有专门的授权码
2、检查代码邮件格式规范
!/usr/bin/env python3
import smtplib
from email.mime.text import MIMEText
import time
mail_server = "smtp.163.com"
mail_port = 25
sender = "xxxxxx@163.com"
sender_password = "xxxxxx" # 授权码
receivers = "xxxxxxxx@163.com"
message = MIMEText('Python邮件发送测试...', 'plain', 'utf-8')
message['From'] = sender
message['To'] = receivers
send_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
subject = '邮件测试' + send_time
message['Subject'] = subject
print (message)
try:
smtp_obj = smtplib.SMTP()
smtp_obj.connect(mail_server, mail_port)
smtp_obj.login(sender, sender_password)
smtp_obj.sendmail(sender, receivers, message.as_string())
print('success!')
except smtplib.SMTPException as e:
print('failure!')
print(e)
网友评论