Last active
June 28, 2017 19:23
-
-
Save sendgrid-gists/516d64061098eb21af72971b8a63cc4a to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with Go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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", "[email protected]") | |
subject := "Sending with SendGrid is Fun" | |
to := mail.NewEmail("Example User", "[email protected]") | |
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