我正在使用 go 發送郵件雜志,我嘗試使用 sendgrid 我嘗試了https://github.com/sendgrid/sendgrid-go中的示例 在 main() 上運行一切正常示例代碼如下package mainimport ( "fmt" "log" "os" "github.com/sendgrid/sendgrid-go" "github.com/sendgrid/sendgrid-go/helpers/mail")func main() { from := mail.NewEmail("Example User", "[email protected]") subject := "Sending with Twilio SendGrid is Fun" to := mail.NewEmail("Example User", "[email protected]") plainTextContent := "and easy to do anywhere, even with Go" htmlContent := "<strong>and easy to do anywhere, even with Go</strong>" message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent) client := sendgrid.NewSendClient(os.Getenv("SENDGRID_API_KEY")) response, err := client.Send(message) if err != nil { log.Println(err) } else { fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers) }}但我需要將 HTML 文本發送到郵件雜志所以我需要修改htmlContent := "<strong>and easy to do anywhere, even with Go</strong>"到htmlContent := "<div>some thing I want to send</div>"所以我做了以下事情func content() string { return fmt.Sprint(`<div>many many html here</div>`)}func main() { key := "my key of sendgrid" send(key)}func send(key string){ from := mail.NewEmail("Example User", "[email protected]") subject := "Sending with Twilio SendGrid is Fun" to := mail.NewEmail("Example User", "[email protected]") plainTextContent := "and easy to do anywhere, even with Go" htmlContent := content() message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent) client := sendgrid.NewSendClient(key) response, err := client.Send(message) if err != nil { fmt.Println("==========send1 failed with",err) } fmt.Println("send1 result") fmt.Println(response.StatusCode) fmt.Println(response.Body) fmt.Println(response.Headers)}func main() { key := "my key here" send(key)}
- 1 回答
- 0 關注
- 178 瀏覽
添加回答
舉報
0/150
提交
取消