Go SDK
Send email with Go
Install the official Parcel Wing Go SDK, configure a server-side API key, and send your first transactional email.
Requirements
- Go 1.22 or newer.
- A Parcel Wing API key stored as
PARCELWING_API_KEY. - A verified sending domain for your
fromaddress.
Install the SDK
The official Go SDK is published as github.com/parcelwing/parcelwing-go.
Terminal
go get github.com/parcelwing/parcelwing-go
Send your first email
Create a parcelwing.Client and call client.Emails.Send.
main.go
package mainimport ("context""fmt""log""os"parcelwing "github.com/parcelwing/parcelwing-go")func main() {client, err := parcelwing.New(os.Getenv("PARCELWING_API_KEY"))if err != nil {log.Fatal(err)}emails, err := client.Emails.Send(context.Background(), parcelwing.EmailSendRequest{From: "Acme <[email protected]>",To: "[email protected]",Subject: "Hello from Parcel Wing",HTML: "<strong>It works!</strong>",Text: "It works.",})if err != nil {log.Fatal(err)}fmt.Println(emails[0].ID)}
Configuration
Set a custom base URL or headers when testing locally or tagging traffic from your app.
client.go
client, err := parcelwing.New(os.Getenv("PARCELWING_API_KEY"),parcelwing.WithBaseURL(os.Getenv("PARCELWING_BASE_URL")),parcelwing.WithHeader("X-App-Name", "acme-go-app"),)
Send to multiple recipients
To accepts either a single email string or a slice of email strings.
bulk.go
emails, err := client.Emails.Send(ctx, parcelwing.EmailSendRequest{From: "Acme <[email protected]>",To: []string{"[email protected]", "[email protected]"},Subject: "Hello from Parcel Wing",Text: "It works!",})
Use a template
Use TemplateAlias and TemplateParams for reusable lifecycle messages.
templates.go
emails, err := client.Emails.Send(ctx, parcelwing.EmailSendRequest{From: "Acme <[email protected]>",To: "[email protected]",TemplateAlias: "welcome",TemplateParams: map[string]any{"first_name": "Ada","plan": "Launch",},})
Handle errors
API and transport failures are returned as *parcelwing.Error.
errors.go
emails, err := client.Emails.Send(ctx, request)if err != nil {if pwErr, ok := err.(*parcelwing.Error); ok {log.Printf("status=%d type=%s code=%s message=%s", pwErr.Status, pwErr.Type, pwErr.Code, pwErr.Message)return}log.Fatal(err)}_ = emails
Framework guides
net/http
Use Parcel Wing from a net/http application with server-side API key handling.
Gin
Use Parcel Wing from a Gin application with server-side API key handling.
Echo
Use Parcel Wing from a Echo application with server-side API key handling.
Fiber
Use Parcel Wing from a Fiber application with server-side API key handling.
Chi
Use Parcel Wing from a Chi application with server-side API key handling.
Gorilla/mux
Use Parcel Wing from a Gorilla/mux application with server-side API key handling.