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!

Refer us and get $10 in 3 simple steps!

Step 1

Get link

Get a free personal referral link here

Step 2

Give $10

Your user signs up and upgrade using link

Step 3

Get $10

1,250 free SMSes
OR 1,000 free voice mins
OR 12,000 chats
OR more