0
我發信用下面的代碼:錯誤的MIME類型EmailMultiAlternatives附件
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,電子郵件客戶端發出預期的警告「:應用/ PDF ;找到:application/octet-stream(.bin)「。爲什麼?
你能打開附件嗎?也許數據必須以特殊的方式進行編碼? Base64左右? – mnille
@mnille是的,如果我將它保存到磁盤。 –
你可以打開該文件,對吧? – mnille