我试图从一个文本字符串而不是外部文件发送电子邮件附件,但附件没有在接收端解码。我使用内置的stringencode函数在base64中对附件进行了编码。我见过许多附加外部文件的示例,但没有看到将字符串作为附件发送的示例。在
为什么附件没有在接收端解码?我是不是对附件编码不当?在
attachment = MIMEText("This is a test".encode('base64', 'strict'))
attachment.add_header('Content-Disposition', 'attachment', 'test.txt')
msg.attach(attachment)
如果确实需要使用
base64
,则应显式设置编码:如果您不需要
^{pr2}$base64
,只需让库为您决定:或者,使用
email.encoders.encode_base64
:您可以参考http://docs.python.org/2/library/email.mime.html?highlight=mimetext#email.mime.text.MIMEText并使用
使用
_subtype
默认的plain
和字符集显式地声明您的编码。在相关问题 更多 >
编程相关推荐