I have been trying to send an HTML email using the Sendgrid API, but I have been unsuccessful in embedding the html inside the json request.
This is an example of the html I am trying to send (emailtpl
):
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body></body></html>
Things I have tried:
- html.EscapeString(emailtpl)
- strconv.Quote(emailtpl)
- using backticks ` inside the json template
- wrapping value with single quotes for the value in the json template.
- base64.StdEncoding.EncodeToString([]byte(emailtpl)) only display the base64 gibberish.
Items #1 and #5 are the only solutions that Sendgrid has accepted, but the html sent is not correct (as shown in the screenshot).
Items #2 - #4 all result in Status 400 Bad Request.
Does anyone know how to embed html into Sendgrid API request that Sendgrid accepts AND it renders correctly?