Google App Engine: how to send html using send_mail

后端 未结 2 1629
忘了有多久
忘了有多久 2021-02-06 15:52

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

2条回答
  •  时光说笑
    2021-02-06 16:38

    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 = '

    Hello!

    ' # 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

提交回复
热议问题