Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send an email in Django with a certain mimetype?

MYMESSAGE = "<div>Hello</div><p></p>Hello"
send_mail("testing",MYMESSAGE,"[email protected]",['[email protected]'],fail_silently=False)

However, this message doesn't get the HTML mime type when it is sent. In my outlook, I see the code...

like image 206
TIMEX Avatar asked Apr 26 '10 09:04

TIMEX


People also ask

How do I send an email to multiple recipients in Django?

How to send multiple mass emails django. We need to create a Tuple of messages and send them using send mass mail. In this tutorial, we create a project which sends email using Django. We fill the data in the form and send it using Django Email.

How do I send an automatic email in Django?

Sending Emails with the Django ShellWe import the Django send_mail function. Then we import the settings object which contains all the global settings and the per-site settings (those inside the settings.py file). Finally, we pass all the needed arguments to the send_mail function.

How do I send an email notification in Django REST framework?

Inside of the “send_mail.py”, create a function that takes in the following arguments. def send_mail(html,text='Email_body',subject='Hello word',from_email='',to_emails=[]): The next step would be to make sure that the “to_emails” argument is always a “list of emails” and not a string or any other data type.


1 Answers

From the docs:

msg = EmailMessage(subject, html_content, from_email, [to])
msg.content_subtype = "html"  # Main content is now text/html
msg.send()

You can only change the subtype of the mimetype it seems. So it will always be

"text/%s" % msg.content_subtype

like image 176
Deniz Dogan Avatar answered Oct 24 '22 13:10

Deniz Dogan