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)
}
Rate this page:

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.

Thank you for your feedback!

Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

thanks-feedback-gif