我试图用一个非常简单的python脚本发送一封带有zip附件的电子邮件,该脚本来自于之前的帖子中找到的答案。在
我的脚本如下:import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
to_addres = "*******"
from_addr = "*******"
mail_server = "*******"
zf = open("/home/******/asd.zip", "rb")
text = '''
Hello,
Here is your test email.
Cheers!
'''
msg = MIMEMultipart(text)
msg.add_header('From', from_addr)
msg.add_header("To", to_addres)
msg.add_header("Subject", "Test")
attachemnt = MIMEBase('application', 'zip')
attachemnt.set_payload(zf.read())
encoders.encode_base64(attachemnt)
attachemnt.add_header('Content-Disposition', 'attachment', filename="asd.zip")
msg.attach(attachemnt)
server = smtplib.SMTP(mail_server, 25)
server.ehlo()
server.sendmail(from_addr, to_addres, msg.as_string())
server.close()
一切似乎都很好,但是当我把邮件从我的供应商发送到一个测试GMAIL帐户时,我被封为垃圾邮件。在
返回的部分错误消息:
^{pr2}$
看来邮件头是空的?怎么会这样?我做错什么了?在