v2 API Go Code Example
We recommend using SendGrid Go, our client library, available on GitHub, with full documentation.
The library does not officially support the V2 API, but you can use V2 with an older version of the library. For more information, see Continue Using V2 in Go.
Using SendGrid's Go Library
// using SendGrid's Go Library
// https://github.com/sendgrid/sendgrid-go
package main
import (
"github.com/sendgrid/sendgrid-go"
)
func main() {
sg := sendgrid.NewSendGridClientWithApiKey("SENDGRID_APIKEY")
message := sendgrid.NewMail()
message.AddTo("test@sendgrid.com")
message.SetFrom("you@youremail.com")
message.SetSubject("Sending with SendGrid is Fun")
message.SetHTML("and easy to do anywhere, even with Go")
sg.Send(message)
}
Need some help?
We all do sometimes. Get help now from the Twilio SendGrid Support Team.
Running into a coding hurdle? Lean on the wisdom of the crowd by browsing the SendGrid tag on Stack Overflow or visiting Twilio's Stack Overflow Collective.