Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MarcBittner/15a1471f027d853fbd7616f9d147bad0 to your computer and use it in GitHub Desktop.
Save MarcBittner/15a1471f027d853fbd7616f9d147bad0 to your computer and use it in GitHub Desktop.
// 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("Marc Bittner", "[email protected]")
from := mail.NewEmail(os.Getenv("SENDGRID_FROM_USERNAME"), os.Getenv("SENDGRID_FROM_EMAIL"))
subject := "Test message sent with SendGrid"
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