1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 解决python发邮件报错(554 'DT:SPM 163 smtp11 D8CowA..

解决python发邮件报错(554 'DT:SPM 163 smtp11 D8CowA..

时间:2024-07-05 00:09:23

相关推荐

解决python发邮件报错(554  'DT:SPM 163 smtp11 D8CowA..

报错信息如下:

将发送人邮箱也加入收件人地址中即可解决报错。

更改之前代码:

import smtplibfrom email.mime.text import MIMETextfrom email.utils import formataddrfrom email.mime.application import MIMEApplicationfrom email.mime.image import MIMEImagefrom email.mime.multipart import MIMEMultipartsender = 'XXX@' # 发件人地址receive = 'XXX@' # 收件人地址passwd = 'XXX' # 授权码mailserver = ''port = '465'sub = 'TEST RESULT' # 邮件主题try:msg = MIMEMultipart('related')msg['From'] = formataddr(["ME", sender])msg['To'] = formataddr(["YOU", receive])msg['Subject'] = subtxt = MIMEText('This is your test result!', 'plain', 'utf-8')msg.attach(txt)# 添加附件,以txt为例,可以改成其他文件格式attach = MIMEApplication(open("D:\xx\hi.txt").read())attach.add_header('Content-Disposition', 'attachment', filename='hi.txt')msg.attach(attach)server = smtplib.SMTP_SSL(mailserver, port)server.login(sender, passwd)server.sendmail(sender, receive, msg.as_string())server.quit()

更改后:

import smtplibfrom email.mime.text import MIMETextfrom email.utils import formataddrfrom email.mime.application import MIMEApplicationfrom email.mime.image import MIMEImagefrom email.mime.multipart import MIMEMultipartsender = 'XXX@' # 发件人地址receive = 'XXX@,XXX@' # 收件人地址 passwd = 'XXX' # 授权码mailserver = ''port = '465'sub = 'TEST RESULT' # 邮件主题try:msg = MIMEMultipart('related')msg['From'] = formataddr(["ME", sender])msg['To'] = formataddr(["YOU,ME", receive])msg['Subject'] = subtxt = MIMEText('This is your test result!', 'plain', 'utf-8')msg.attach(txt)# 添加附件,以txt为例,可以改成其他文件格式attach = MIMEApplication(open("D:\xx\hi.txt").read())attach.add_header('Content-Disposition', 'attachment', filename='hi.txt')msg.attach(attach)server = smtplib.SMTP_SSL(mailserver, port)server.login(sender, passwd)server.sendmail(sender, receive, msg.as_string())server.quit()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。