Created
May 22, 2024 03:57
-
-
Save MarcBittner/15a1471f027d853fbd7616f9d147bad0 to your computer and use it in GitHub Desktop.
This file contains 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("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