2016-02-16 48 views
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)「。爲什麼?

+0

你能打開附件嗎?也許數據必須以特殊的方式進行編碼? Base64左右? – mnille

+0

@mnille是的,如果我將它保存到磁盤。 –

+0

你可以打開該文件,對吧? – mnille

回答

0

我覺得自己很愚蠢。問題是兩個錯誤的結果。首先,附件名稱應該有擴展名!其次,RoundCube必須使用PHP和mime_magic。