A
A
alexit2282021-03-07 23:44:39
Python
alexit228, 2021-03-07 23:44:39

How to send html email to gmail in python?

I add html content.

content = Content('text/html', params.get('body'))
message.add_content(content)

However, html tags are replaced with characters. How can this be fixed?
60453b333c8b3975837328.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iBird Rose, 2021-03-08
@iiiBird

https://docs.python.org/3/library/html.html#html.u...

G
galaxy, 2021-03-08
@galaxy

The documentation for your sendgrid is lousy, but I think that you need to add a text version before the html version of the letter:

body = params.get('body')
txt_body = ... # перевести в текст, например через html2text: https://pypi.org/project/html2text/
message.add_content(txt_body , 'text/plain')
message.add_content(body, 'text/html')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question