在golang中使用发送网格?

I use sendgrid to send mail in golang. Although status code return 202, email don't send. Can someone help me?

package main

import (
    "fmt"
    "log"

    sendgrid "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 SendGrid is Fun"
    to := mail.NewEmail("Example User", "trungduc08trungduc08@gmail.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("my api-key")
    response, err := client.Send(message)
    if err != nil {
        log.Println("err:", err)
    } else {
        fmt.Println("statusCode: ", response.StatusCode)
        fmt.Println("body: ", response.Body)
        fmt.Println("headers: ", response.Headers)
    }
}

I assume you have set up a SendGrid account, if not, I would start there as it has step by step instructions on how to generate a API key and test that your email has been sent by SendGrid.

Your issue is on this line (the code above looks to be pulled directly from SendGrid's example unmodified)

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

The email address must be a valid email address that you control.

See https://app.sendgrid.com/guide/integrate/langs/go for more details on how to get started.

If the above doesn't work it may also need to be validated/verified by SendGrid (you would have received a verification email when you nominated an email address for sending emails under Marketing > Marketing Campaigns > Senders > Create New Sender in your SendGrid account) before you can send emails using that email address.