我使用GO并尝试通过sendgrid API v3(https://github.com/sendgrid/sendgrid-go没有Mail Helper Class)发送邮件。但是当我使用这段代码时:
"content": [
{
"type": "text/html",
"value": "<html><head></head><body>Hello You link <a href="http://example.com/reschedule?id=12334">Click</a></body></html>"
}
],
我收到错误:
400 {&#34;错误&#34;:[{&#34;消息&#34;:&#34;错误请求&#34;&#34;字段&#34;:null,&#34;帮助&#34;:空}]}
但是这段代码可以正常工作:
"content": [
{
"type": "text/html",
"value": "<html><head></head><body>Hello!</body></html>"
}
],
我认为特殊字符有问题,但我怎么能解决它?谢谢!
答案 0 :(得分:1)
需要这样做:
<div class=\"ad_box\"><img class=\"banner\" src=\"some_ad.png\" alt=\"\" \/>
Example
"content": [
{
"type": "text/html",
"value": "<html><head></head><body>Hello You link <a href=\"http://example.com/reschedule?id=12334\">Click</a></body></html>"
}
],
答案 1 :(得分:0)
我遇到了同样的问题,相同的转义符,解决的办法是使用官方客户端及其助手。
示例代码:
from := mail.NewEmail("from", "from@mail.com")
to := mail.NewEmail("to", "to@mail.com")
content := mail.NewContent("text/html", contentHtml)
email := mail.NewV3MailInit(from, "Sample about sendgrid client", to, content)
personalization := mail.NewPersonalization()
personalization.AddTos(to)
email.AddPersonalizations(personalization)
client := sendgrid.NewSendClient(os.Getenv("SENDGRID_API_KEY"))
response, err = client.Send(email)
if err != nil {
return fmt.Errorf("Cannot send the email: %v", err)
}
if response.StatusCode != 202 {
return fmt.Errorf("Cannot send the email: %s", response.Body)
}