sendgrid html text,go - Send HTML content via SendGrid v3 - Stack Overflow

I was having the same problem, same escapes special characters, what solved was to use the official client to go and its helpers.

Sample code:

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)

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值