sendgrid go 发送获取错误意外的 EOF

我正在使用 go 发送邮件杂志,我尝试使用 sendgrid 我尝试了https://github.com/sendgrid/sendgrid-go中的示例 在 main() 上运行一切正常

示例代码如下

package main


import (

    "fmt"

    "log"

    "os"


    "github.com/sendgrid/sendgrid-go"

    "github.com/sendgrid/sendgrid-go/helpers/mail"

)


func main() {

    from := mail.NewEmail("Example User", "test@example.com")

    subject := "Sending with Twilio SendGrid is Fun"

    to := mail.NewEmail("Example User", "test@example.com")

    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", "test@example.com")

    subject := "Sending with Twilio SendGrid is Fun"

    to := mail.NewEmail("Example User", "xu1718191411@yahoo.co.jp")

    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)

}


米琪卡哇伊
浏览 145回答 1
1回答

萧十郎

我使用了测试帐户。而且它每天只允许我发送 100 封邮件。我开始付款,然后它就消失了。怪sendgrid反应不佳。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go