给单个人地址发就没问题,多人 list 就不行了。
这是报错内容
Error in functon : " send_text_email " ,
Error name is : " SMTPDataError " ,
Error type is : " <class 'smtplib.SMTPDataError'> " ,
Error Message is : " (554, 'DT:SPM 126 smtp2,DMmowECZeEbGLkNX_iNcAA--.205S2 1464020678,please see http://mail.163.com/help/help_spam_16.htm?ip=123.150.243.7&hostid=smtp2&time=1464020678') " ,
Error doc is : " The SMTP server didn't accept the data. " ,
msg 内容
From nobody Tue May 24 00:24:38 2016
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
From: =?utf-8?b?5rWL6K+V5py65Zmo5Lq6?= <leisurelylicht@126.com>
Subject: test
To: leisurelylicht@126.com,licht00@163.com
aW5mbw==
主要代码
def send_text_email(self, title, message, message_type):
"""
发送文本邮件
没有返回值
函数内调用_format_address()
:param message_type:
:param message:
:param title:
"""
print 'send_text_email %s ' % title
msg = MIMEText(message, 'plain', 'utf-8')
msg['From'] = self._format_address(u'%s<%s>' % (self.mailName, self.sender))
msg['Subject'] = Header(title)
while 1:
try:
smtp = smtplib.SMTP()
# smtp.set_debuglevel(1)
print '开始尝试连接邮箱'
smtp.connect(self.smtp_server, self.smtp_server_port)
print '成功连接邮箱'
print '开始尝试登陆邮箱'
smtp.login(self.username, self.password)
print '成功登陆邮箱'
if message_type == "securityInfo":
print '开始发送事件邮件'
msg['To'] = ','.join(self.receiver)
print 'msg', msg
smtp.sendmail(self.sender, self.receiver, msg.as_string())
print '成功发送事件邮件'
except smtplib.SMTPAuthenticationError:
print '认证失败,邮箱连接可能出问题了'
self.count += 1
if self.count < 3:
time.sleep(10)
continue
else:
print '更换邮箱后重试...'
self.Mail_choose = not self.Mail_choose
self.mail_init()
self.count = 0
continue
except Exception as e:
error_text = exception_format(get_current_function_name(), e)
print error_text
time.sleep(10)
continue
else:
smtp.quit()
self.count = 0
break
求各位指教
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.