Go SDK
Send email with Echo
Use Parcel Wing from Echo handlers and request-scoped contexts.
Install the SDK
The official Go SDK is published as github.com/parcelwing/parcelwing-go.
Terminal
go get github.com/parcelwing/parcelwing-go
Echo handler
Create the Parcel Wing client during server startup, then reuse it from trusted server-side handlers.
main.go
package mainimport ("net/http""os""github.com/labstack/echo/v4"parcelwing "github.com/parcelwing/parcelwing-go")func main() {client, err := parcelwing.New(os.Getenv("PARCELWING_API_KEY"))if err != nil {panic(err)}e := echo.New()e.POST("/send-welcome", func(c echo.Context) error {payload := map[string]string{}if err := c.Bind(&payload); err != nil {return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid json"})}emails, err := client.Emails.Send(c.Request().Context(), parcelwing.EmailSendRequest{From: os.Getenv("PARCELWING_FROM_EMAIL"),To: payload["email"],TemplateAlias: "welcome",TemplateParams: map[string]any{"first_name": payload["first_name"]},})if err != nil {return c.JSON(http.StatusBadGateway, map[string]string{"error": err.Error()})}return c.JSON(http.StatusOK, map[string]any{"id": emails[0].ID})})e.Logger.Fatal(e.Start(":8080"))}
Production notes
- Keep
PARCELWING_API_KEYin server-side environment variables. - Use the incoming request context where available so sends can respect request cancellation.
- Log structured
*parcelwing.Errorfields for support and debugging.