错误的mime类型的EmailMultiAlternatives附件

时间:2016-02-16 08:54:38

标签: django email mime-types mime

我发送的信件中包含以下代码:

txt_msg_body = get_template('{0}.txt'.format(template_name)).render(ctx)
html_msg_body = get_template('{0}.html'.format(template_name)).render(ctx)
msg = EmailMultiAlternatives(subject, txt_msg_body, smtp_from, recipients)
msg.attach_alternative(html_msg_body, "text/html")
...
with open(file_path, 'rb') as fh:
    data = fh.read()
...
msg.attach(name, data, 'application/pdf')
msg.send()

尽管明确指定了参数 content_type ,但电子邮件客户端会发出警告“Expected:application / pdf; found:application / octet-stream(.bin)”。为什么呢?

1 个答案:

答案 0 :(得分:0)

我觉得自己太愚蠢了。问题是两个错误的结果。首先,附件名称应该有扩展名!其次,RoundCube必须将PHP与mime_magic一起使用。

相关问题