Sign inGet Started

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 from address.

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 main
 
import (
"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]>",
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]>",
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]>",
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