【发布时间】:2013-10-31 18:25:19
【问题描述】:
我正在尝试从文本字符串而不是外部文件发送电子邮件附件,但附件未在接收端解码。我使用内置的字符串编码功能在 base64 中对附件进行了编码。我见过很多附加外部文件的示例,但我还没有看到将字符串作为附件发送的示例。
为什么附件没有在接收端解码?我是否对附件进行了不正确的编码?
attachment = MIMEText("This is a test".encode('base64', 'strict'))
attachment.add_header('Content-Disposition', 'attachment', 'test.txt')
msg.attach(attachment)
【问题讨论】: