Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sendgrid go发送获取错误意外EOF_Go_Sendgrid - Fatal编程技术网

sendgrid go发送获取错误意外EOF

sendgrid go发送获取错误意外EOF,go,sendgrid,Go,Sendgrid,我正在使用go发送邮件杂志,并尝试使用sendgrid 我试了一些样品 在main上运行一切正常 示例代码如下所示 package main import ( "fmt" "log" "os" "github.com/sendgrid/sendgrid-go" "github.com/sendgrid/sendgrid-go/helpers/mail" ) func main() { from := mail.NewEmail("Examp

我正在使用go发送邮件杂志,并尝试使用sendgrid 我试了一些样品 在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)
    }
}

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)
}


func send(key string){
    from := mail.NewEmail("Example User", "test@example.com")
    subject := "Sending with Twilio SendGrid is Fun"
    to := mail.NewEmail("Example User", "my email")
    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)
}

似乎如果HTML字符串的长度超过某个长度,就会出现意外的EOF

如果我只发送几个Html字符串,这个过程就会顺利进行

还有这个

2019/10/03 17:31:47 length of the html string length
2019/10/03 17:31:47 2402
==========send1 failed with unexpected EOF
send1 result
401

map[Content-Type:[application/json] Content-Length:[76] Connection:[keep-alive] Access-Control-Allow-Origin:[https://sendgrid.api-docs.io] Access-Control-Max-Age:[600] Server:[nginx] Date:[Thu, 03 Oct 2019 08:31:47 GMT] Access-Control-Allow-Methods:[POST] Access-Control-Allow-Headers:[Authorization, Content-Type, On-behalf-of, x-sg-elas-acl] X-No-Cors-Reason:[https://sendgrid.com/docs/Classroom/Basics/API/cors.html]]
send1_with_mini_data result

我的环境 转到1.11.6

sendgrid 3.1.0


有人能帮我吗?

我使用了一个测试帐户。它每天只允许我发送100封邮件。我开始付钱,然后就没了

归咎于反应差

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)
}


func send(key string){
    from := mail.NewEmail("Example User", "test@example.com")
    subject := "Sending with Twilio SendGrid is Fun"
    to := mail.NewEmail("Example User", "my email")
    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)
}

==========send1 failed with unexpected EOF
send result
401

map[Access-Control-Allow-Methods:[POST] Access-Control-Allow-Headers:[Authorization, Content-Type, On-behalf-of, x-sg-elas-acl] Date:[Thu, 03 Oct 2019 08:01:36 GMT] Content-Length:[76] Connection:[keep-alive] Access-Control-Max-Age:[600] X-No-Cors-Reason:[https://sendgrid.com/docs/Classroom/Basics/API/cors.html] Server:[nginx] Content-Type:[application/json] Access-Control-Allow-Origin:[https://sendgrid.api-docs.io]]
send1_with_mini_data result


func content() string {
    return fmt.Sprint(`<div>one word</div> `)
}


func content() string {
    result := fmt.Sprint(`<div>some html string</div> `)
    log.Print("length of the html string length")
    log.Print(len(result))
}

2019/10/03 17:31:05 length of the html string length
2019/10/03 17:31:05 2401
send1 result
401
{"errors":[{"message":"Maximum credits exceeded","field":null,"help":null}]}
map[Date:[Thu, 03 Oct 2019 08:31:05 GMT] Content-Type:[application/json] Content-Length:[76] Connection:[keep-alive] Access-Control-Allow-Origin:[https://sendgrid.api-docs.io] X-No-Cors-Reason:[https://sendgrid.com/docs/Classroom/Basics/API/cors.html] Server:[nginx] Access-Control-Allow-Methods:[POST] Access-Control-Allow-Headers:[Authorization, Content-Type, On-behalf-of, x-sg-elas-acl] Access-Control-Max-Age:[600]]
send1_with_mini_data result

2019/10/03 17:31:47 length of the html string length
2019/10/03 17:31:47 2402
==========send1 failed with unexpected EOF
send1 result
401

map[Content-Type:[application/json] Content-Length:[76] Connection:[keep-alive] Access-Control-Allow-Origin:[https://sendgrid.api-docs.io] Access-Control-Max-Age:[600] Server:[nginx] Date:[Thu, 03 Oct 2019 08:31:47 GMT] Access-Control-Allow-Methods:[POST] Access-Control-Allow-Headers:[Authorization, Content-Type, On-behalf-of, x-sg-elas-acl] X-No-Cors-Reason:[https://sendgrid.com/docs/Classroom/Basics/API/cors.html]]
send1_with_mini_data result