I have a app with a kind of rest api that I\'m using to send emails . However it currently sends only text email so I need to know how to modify it and make it send html . Below
Have a look to the Email message fields of the send_mail
function.
Here is the parameter you need:
html
An HTML version of the body content, for recipients that prefer HTML email.
You should add the html
input parameter like this:
#Your html body
mail_html_body = '<h1>Hello!</h1>'
# read data from request
mail_to = str(self.request.POST.get('to'))
mail_from = str(self.request.POST.get('from'))
mail_subject = str(self.request.POST.get('subject'))
mail_body = str(self.request.POST.get('body'))
mail.send_mail(mail_from,
mail_to,
mail_subject,
mail_body,
html = mail_html_body ) #your html body
you can use the html field of EmailMessage class
message = mail.EmailMessage(sender=emailFrom,subject=emailSubject)
message.to = emailTo
message.body = emailBody
message.html = emailHtml
message.send()