关于smtplib发送邮件报错的问题:SMTPDataError: (554, 'DT:SPM 163 smtp1

我在发送邮件的时候!授权码各方面都写正确了!但是却遇到下面那个异常!

raise SMTPDataError(code, resp)
SMTPDataError: (554, 'DT:SPM 163 smtp14,EsCowABXOeQy9p5hou3fMw--.131S2 1637807667,please see http://mail.163.com/help/help_spam_16.htm?ip=118.193.105.240&hostid=smtp14&time=1637807667')

开始以为是传送的文本的内容有问题!被当成了是垃圾邮件不允许发送!然后改了很多次都不行!后来找了很久!才发现是From 和 To 的坑!

有问题的代码:
import smtplib
from email.mime.text import MIMEText from email.header import Header mail_host="smtp.163.com" mail_user="*******.com" mail_pass="*******" sender = '******@163.com' receivers = ['******@qq.com','******@163.com'] body_content = """ 测试文本 """ message = MIMEText(body_content, 'plain', 'utf-8') message['From'] = "********@163.com" message['To'] = "******@qq.com" subject = """

改为:

message['Subject'] = Header(subject, 'utf-8')
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25)
smtpObj.set_debuglevel(1)
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
smtpObj.quit()
这里的message['From'] 和To 改为 邮箱里收发邮件的发件人和收件人那种字符格式!

message['From'] = "wumian<**********@163.com>"
message['To'] = "qishi<**********@qq.com>"

就可以了!!!!!!!!!!!!!!

posted @ 2021-11-25 11:33  王二黑  阅读(930)  评论(0编辑  收藏  举报