0

I am using EmailMessage to send mail with an attachment. That attachment is .html file. I am successful in attaching the file in the email. But that html is not display properly. Html file is showing some tag in the attachment content.

Code return is as follows,

attach_file_name is the file path which I want to display i.e. "/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()

Please Help Me

Mugdha
  • 851
  • 2
  • 9
  • 12

2 Answers2

1

You need use 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()
nnmware
  • 930
  • 5
  • 15
  • Thanks for answer. I tried this also but it is not work for me. In the html file some tags are available like which are deprecated this will create any problem?? – Mugdha Aug 08 '13 at 04:20
  • YOu can still use font tags even though they're deprecated. – Brandon Taylor Aug 08 '13 at 13:24
0

I read the file with help of BeautifulSoup and then I attach that file to email then html is coming in proper format

Mugdha
  • 851
  • 2
  • 9
  • 12