Python-已发送的 MIME 电子邮件附件未显示在 mail.live 中

Python-sent MIME email attachments not showing up in mail.live

我有一个 Python 3 脚本,它使用 MIMEMultipart 发送一封电子邮件,其中附有它生成的 .xlsx 文件。我曾经在 Py2 上使用相同的脚本来发送相同的生成文件,唯一的区别是 Py2 脚本从 MySQL 收集信息来创建 .xlsx 而 Py3 脚本使用 PostgreSQL。

msg = MIMEMultipart('alternative')
msg.attach(MIMEText("""HTML stuff""", 'html'))

with open(analysis_file, "rb") as fil:
  msg.attach(MIMEApplication(
                    fil.read(),
                    Content_Disposition='attachment; filename="%s"' % os.path.basename(analysis_file),
                    Name=os.path.basename(analysis_file)
                ))

msg['Subject'] = "SUBJECT"
msg['From']="Me <me@me.com>"
msg['To']= "You <you@you.com>"

server.sendmail(FROMADDR, ["you@you.com"], msg.as_string())

然而,当我切换到脚本的 Py3 版本时,附件停止显示在 Microsoft 的 mail.live 上。表示邮件有附件的回形针符号仍然出现,但我找不到它。

--编辑:

如果我设置自动转发到 Gmail 帐户,.xlsx 附件通常会在那里显示;但是,如果我手动转发它,它不会。

帮我一个忙,测试它是否适用于 yagmail。对于做 HTML/attachments 的东西,我认为它真的很有用:默认是在 HTML 中发送东西,附件可以通过指向路径来完成。

全部代码:

import yagmail
yag = yagmail.SMTP('me@me.com', 'password')
yag.send("you@you.com", "SUBJECT", analysis_file)

send中的第三个字段是内容,它可以是一个字符串列表,也可以只是一个字符串。如果字符串可以作为文件加载,它会被简单地附加。

有关详细信息,请查看 github 页面。请注意,我是 developer/maintainer.

改变

msg = MIMEMultipart('alternative')

msg = MIMEMultipart('html')

已修复。