message['Subject'] = Header(subject, 'utf-8') message.attach(MIMEText(contents, 'plain', 'utf-8'))
if filename is not None and path is not None:
attach_file = MIMEText(open(path, 'rb').read(), 'base64', 'utf-8')
attach_file["Content-Type"] = 'application/octet-stream'
attach_file.add_header('Content-Disposition', 'attachment', filename=('gb2312', '', filename))
message.attach(attach_file)
try:
result = True
errors = ''
if int(usessl):
smtpObj = smtplib.SMTP_SSL(mail_host, port)
else:
smtpObj = smtplib.SMTP(mail_host, port)
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
这是我邮件主要的代码、目前用各个邮箱的网页端接收邮件和附件都是正常的。但是用 windows 端的 outlook 客户端接收邮件的时候就会出现问题 附件的名称会被改成 Attachment_1.txt 而不是原来的名称和后缀 跟各位大佬请教一下 这个是要在哪里加什么东西吗 = = 我被困扰好久了
Python3 MacOS 和 Linux7 环境下
1
nightstart OP 上浮
|
2
nightstart OP 上浮 1
|