Python emailmultialternatives在django中附加文件和html内容

Python emailmultialternatives在django中附加文件和html内容,python,django,Python,Django,我尝试使用emailmultialternations以html格式发送电子邮件,并且 文本。我还想在这封电子邮件中包含一个文件 但后者似乎删除了我的html内容 这是我的密码: msg = EmailMultiAlternatives(subject, html2text(html_content), list(email_from), list(email_to), attachments=((request.session['customer']+".txt.blowfish", r

我尝试使用
emailmultialternations
html
格式发送电子邮件,并且 文本。我还想在这封电子邮件中包含一个文件

但后者似乎删除了我的html内容

这是我的密码:

msg = EmailMultiAlternatives(subject, html2text(html_content), 
list(email_from), list(email_to), 
attachments=((request.session['customer']+".txt.blowfish", 
request.session["customer"].content),)) 

msg.attach_alternative(html_content, "text/html") 

msg.send() 
我使用最新的SVN版本 我还尝试使用
msg.attact()
代替附件,结果相同

发送替代文本内容,但不发送html内容。只是 显示文件

任何线索都将不胜感激,

我也有同样的问题

我用于将文件附加到HTML电子邮件的代码是:

email_dict = {}
email_dict['user'] = user                       

t = loader.get_template('emails/myemail.html')
html = t.render(Context(email_dict))

msg = EmailMultiAlternatives(subject='My Subject', 
                             body=html, 
                             from_email=settings.DEFAULT_FROM_EMAIL, 
                             to=['my_email@email.com'],) 

attachment = open('filepath', 'rb')
msg.attach('Name.txt', attachment.read(), 'text/csv')

msg.content_subtype = 'html'
msg.send()
所以,也许这样的事情对你有用:

msg = EmailMultiAlternatives(subject=subject, 
                             body=html2text(html_content), 
                             from_email=list(email_from), 
                             to=list(email_to))


attachment = open(request.session['customer']+".txt.blowfish", 'rb')
msg.attach('Name.txt.blowfish', attachment.read(), 'text/plain')

msg.content_subtype = 'html'
msg.send()

我希望这有帮助

就是这么完美的答案。。!文件: