Go
Send your first message from a Go project with the official Postwick library.
Use this ready-made prompt to wire Postwick into your project
Add the Postwick Go SDK to this project, read POSTWICK_API_KEY from the environment and send a test email to delivered@postwick.dev.Prerequisites
Before you begin you need:
A Postwick API key
Guide
- Install
Add the library to your project.
go get github.com/postwick/postwick-go - Store your API key
Keep the key out of source control by putting it in an environment variable.
.env POSTWICK_API_KEY=pw_live_4f9c2e7a1b - Send an email
The smallest useful call takes a sender, a recipient, a subject and a body.
main.go package main import ( "fmt" "os" "github.com/postwick/postwick-go" ) func main() { client := postwick.NewClient(os.Getenv("POSTWICK_API_KEY")) sent, err := client.Emails.Send(&postwick.SendEmailRequest{ From: "Lumen <hello@mail.lumen.dev>", To: []string{"ada@example.com"}, Subject: "Your receipt from Lumen", Html: "<p>Thanks for your order, Ada.</p>", }) if err != nil { panic(err) } fmt.Println(sent.Id) }
Examples
Updated