Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

v3 API Go Code Example


(information)

Info

We recommend using SendGrid Go, our client library, available on GitHub(link takes you to an external page), with full documentation.

(information)

Info

Do you have an API Key(link takes you to an external page) yet? If not, go get one. You're going to need it to integrate!


Using SendGrid's Go Library

using-sendgrids-go-library page anchor

_30
// using SendGrid's Go Library
_30
// https://github.com/sendgrid/sendgrid-go
_30
package main
_30
_30
import (
_30
"fmt"
_30
"log"
_30
"os"
_30
_30
"github.com/sendgrid/sendgrid-go"
_30
"github.com/sendgrid/sendgrid-go/helpers/mail"
_30
)
_30
_30
func main() {
_30
from := mail.NewEmail("Example User", "test@example.com")
_30
subject := "Sending with SendGrid is Fun"
_30
to := mail.NewEmail("Example User", "test@example.com")
_30
plainTextContent := "and easy to do anywhere, even with Go"
_30
htmlContent := "<strong>and easy to do anywhere, even with Go</strong>"
_30
message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent)
_30
client := sendgrid.NewSendClient(os.Getenv("SENDGRID_API_KEY"))
_30
response, err := client.Send(message)
_30
if err != nil {
_30
log.Println(err)
_30
} else {
_30
fmt.Println(response.StatusCode)
_30
fmt.Println(response.Body)
_30
fmt.Println(response.Headers)
_30
}
_30
}


Rate this page: