Skip to content

Instantly share code, notes, and snippets.

@sendgrid-gists
Last active June 28, 2017 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sendgrid-gists/516d64061098eb21af72971b8a63cc4a to your computer and use it in GitHub Desktop.
Save sendgrid-gists/516d64061098eb21af72971b8a63cc4a to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with Go.
// using SendGrid's Go Library
// https://github.com/sendgrid/sendgrid-go
package main
import (
"fmt"
"log"
"os"
"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", "test@example.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(os.Getenv("SENDGRID_API_KEY"))
response, err := client.Send(message)
if err != nil {
log.Println(err)
} else {
fmt.Println(response.StatusCode)
fmt.Println(response.Body)
fmt.Println(response.Headers)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment