使用python 发送邮件,为什么会被认为垃圾邮件

如题所述

我在 csdn 和 cnblog 找到关于 python 发送邮件的例子,代码如下。但在执行时却返回 554 DT.SPM 的错误,上网找原因是对方服务器认为是垃圾邮件而拒收了。还有,关于代码中 msg['To']=';'.join(to_list) 是什么意思?我该如何理解这行代码?

#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText

mailto_list="[email protected]"

mail_host="smtp.163.com"
mail_user="xxx"
mail_pass="xxx"
mail_postfix="163.com"

def send_mail(to_list, sub, content):
me="Ryan Mok"+"<"+mail_user+"@"+mail_postfix+">"
msg=MIMEText(content, _subtype='plain',_charset='gb2312')
msg['Subject']=sub
msg['From']=me
msg['To']=';'.join(to_list)
try:
server=smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user,mail_pass)
server.sendmail(me,to_list,msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False

if __name__ == '__main__':
if send_mail(mailto_list,"This is test mail","This is a test email send from python."):
print "Send succeed!\n"
else:
print "Send failed!\n"
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-08-01
header没写全吧
相似回答