0

我正在使用 EmailMessage 发送带有附件的邮件。该附件是 .html 文件。我成功地在电子邮件中附加了文件。但是那个 html 不能正确显示。Html 文件在附件内容中显示了一些标签。

代码返回如下,

attach_file_name 是我要显示的文件路径,即“/path/of/html/file.html”

msg = EmailMessage(subject, content, from_email, to_list, cc=cc_list, bcc=bcc_list)
if attach_file_name:
    msg.attach_file(attach_file_name)
msg.content_subtype = "html"
msg.send()

请帮我

4

2 回答 2

1

您需要使用 EmailMultiAlternatives

from django.core.mail import EmailMultiAlternatives

msg = EmailMultiAlternatives(subject, content, from_email, to_list, cc=cc_list, bcc=bcc_list)
if attach_file_name:
    msg.attach_file(attach_file_name, mimetype="text/html")
msg.send()
于 2013-08-07T18:57:34.067 回答
0

我在 BeautifulSoup 的帮助下阅读了该文件,然后将该文件附加到电子邮件中,然后 html 以正确的格式出现

于 2013-08-09T05:05:45.573 回答