Go SDK

The official camelmailer-go module has zero dependencies and uses the stdlib only. Every method takes a context.Context and respects cancellation and deadlines.

Install

terminal
go get github.com/camelmailer/camelmailer-go

Requires Go 1.21+.

Quickstart

main.go
client := camelmailer.NewClient("cm_xxxx")

sent, err := client.Emails.Send(ctx, &camelmailer.SendEmailRequest{
    From:     camelmailer.Address{Email: "billing@acme.com"},
    To:       []camelmailer.Address{{Email: "ada@example.com"}},
    Subject:  "Your receipt",
    TextBody: "Thanks for your purchase.",
})

Send with a template

template.go
sent, err := client.Emails.SendWithTemplate(ctx, &camelmailer.SendWithTemplateRequest{
    SendEmailRequest: camelmailer.SendEmailRequest{
        From: camelmailer.Address{Email: "hello@acme.com"},
        To:   []camelmailer.Address{{Email: "ada@example.com"}},
    },
    Template:      "welcome",
    TemplateModel: map[string]any{"name": "Ada"},
})

Error handling

Every API failure is a typed *camelmailer.APIError with the stable error code and HTTP status.

errors.go
sent, err := client.Emails.Send(ctx, req)
if err != nil {
    var apiErr *camelmailer.APIError
    if errors.As(err, &apiErr) {
        switch apiErr.Code {
        case "ValidationError", "ParameterMissing":
            // fix the request
        case "Unauthorized":
            // check the API key
        }
    }
}

Self-hosted instances

The client defaults to the cloud. Point it at your own instance with WithBaseURL:

self-hosted.go
client := camelmailer.NewClient("cm_xxxx",
    camelmailer.WithBaseURL("https://mail.example.com"),
    camelmailer.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}),
)
Full field reference: Messages API.

GitHub repository · pkg.go.dev reference