解决Python使用139邮箱报错smtplib.SMTPDataError: (550, b‘2f0d645e15038f4

阅读: 评论:0

解决Python使用139邮箱报错smtplib.SMTPDataError: (550, b‘2f0d645e15038f4

解决Python使用139邮箱报错smtplib.SMTPDataError: (550, b‘2f0d645e15038f4

封装了一个邮件发送类,负责建立连接并发送邮件。

import smtplib
from datetime import datetime
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from  import MIMEText
from email.header import Headerclass Mail:# 登录及服务器信息mail_host = None    # 邮箱服务器地址mail_port = None    # 邮箱服务端口sender    = None    # 发送者(邮箱账号)authCode  = None    # 授权码receivers = None    # 接收者ccs       = None    # 抄送者# 邮箱连接mailServerCon = None# 邮件对象envelope = Nonedef __init__(self, mailhost, mailport, authCode, sender, receivers, cc):''':param authCode:授权码:param sender:发送者(邮箱账号):param receivers:接受者,多个接受者用英文分号分隔:param cc:抄送者,多个抄送者用英文分号分隔'''Mail.mail_host = mailhostMail.mail_port = mailportMail.authCode = authCodeMail.sender = ivers = receiversMails = ccdef login(self):# 连接邮箱服务器Mail.mailServerCon = smtplib.SMTP_SSL(Mail.mail_host, Mail.mail_port)# 登录邮箱Mail.mailServerCon.login(Mail.sender, Mail.authCode)def write(self, title, content, attachment=[]):''':param title: 邮件的主题:param content: 邮件的内容:param attachment: 邮件的附件,字符列表对象,附件的绝对路径:return:'''# 1.创建邮件对象velope = MIMEMultipart()# 2.设置邮件主题subject = Header(title, 'utf-8').encode()velope['Subject'] = subject# 3.设置邮件发送者velope['From'] = Mail.sender# 4.设置邮件抄送者if Mails is not None and Mails !="":velope['Cc'] = Mails# 4.设置邮件接收者velope['To'] = ivers# 5.添加文字内容body = MIMEText(content, 'plain', 'utf-8') # 类型:plain(简单的⽂字内容)、html(超文本) 邮件对象.attach(文字对象)velope.attach(body)# 6.添加附件for filepath in attachment:filename = filepath[filepath.rfind("/")+1:]annex = MIMEApplication(open(filepath, 'rb').read())annex["Content-Type"] = 'application/octet-stream'     # 设置内容类型annex.add_header('Content-Disposition', 'attachment', filename=filename) # 添加到header信息velope.attach(annex)def send(self):receivers = iversif Mails is not None and Mails !="":receivers = receivers+";"+MailsMail.mailServerCon.sendmail(Mail.sender, receivers.split(";"), velope.as_string())Mail.mailServerCon.quit()if __name__ == '__main__':# 执行邮件发送mailhost = "smtp.139"mailport = 465mailauthcode = "8baxxxxxxxxxxxxx00"             # 授权码mailsender = "182xxxxxxxx@139"              # 发送方邮箱mailreceiver = "xxxxx@qq;yyyyyy@qq"     # 收件人邮件mailcc = ""        # 抄送人邮箱mail = Mail(mailhost, mailport, mailauthcode, mailsender, mailreceiver, mailcc)mail.login()huaweiOutputName = dataPath + "文件1.xlsx"zteOutputName = dataPath + "文件2.xlsx"attachments = [huaweiOutputName, zteOutputName]curTime = w()formCurTime = curTime.strftime('%Y-%m-%d %H:%M:%S')mail.write("【XXX分析】,第"+str(1)+"次", "分析时间:"+formCurTime, attachments)mail.send()print("邮件发送成功...")

运行报错如下:

smtplib.SMTPDataError: (550, b'2f0d645e15038f4-1891b Mail rejected')

经过检查,发现是139邮箱的设置有问题,错误设置如下图:

 邮箱协议设置中,两个邮箱是都打开的。

经过实测,修改为只打开下一个“开启IMAP/SMTP服务”,入下图所示,就可以发送成功。

到此,结束。

本文发布于:2024-03-25 14:59:27,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/1731184519498982.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:报错   邮箱   Python   SMTPDataError   smtplib
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23