Skip to content Skip to sidebar Skip to footer

Google App Engine: How To Send Html Using Send_mail

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 is

Solution 1:

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

Solution 2:

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()

Post a Comment for "Google App Engine: How To Send Html Using Send_mail"