Go

Send email from Go

go get mailset.app/go, then client.Send(ctx, mailset.Message{...}). The module needs nothing outside the standard library, and every input and answer is a struct.

Open Mailset
Continue with Google

By starting you agree to the Terms and Privacy Policy.

Install

Install the Go SDK

One module, for Go 1.22 and later. Nothing else lands in your go.sum because of it.

go get
go get mailset.app/[email protected]
Send

Send your first email from Go

mailset.NewClient() reads MAILSET_KEY and returns an error when it finds no credential. Send takes a context and a mailset.Message; mailset.Within(10 * time.Minute) sets its deadline, so a code that can’t go out in time is refused. The receipt carries ID and Status.

main.go
import (
	"context"
	"fmt"
	"log"
	"time"

	mailset "mailset.app/go"
)

client, err := mailset.NewClient() // reads MAILSET_KEY
if err != nil {
	log.Fatal(err)
}
ctx := context.Background()

sent, err := client.Send(ctx, mailset.Message{
	From:      "Acme <moc.elpmaxe@olleh>",
	To:        []string{"gro.elpmaxe@ana"},
Webhooks

Delivery events with net/http

hook is a plain handler. It reads the body with io.ReadAll before anything decodes it, since the signature covers those bytes, and mailset.VerifyWebhookHeader checks them against r.Header. A failed check is a *mailset.Error, answered 401. 204 tells Mailset the batch is kept; until then it posts the batch again.

main.go
import (
	"errors"
	"io"
	"log"
	"net/http"
	"os"

	mailset "mailset.app/go"
)

// hook is Mailset's webhook endpoint, a plain
// net/http handler.
func hook(w http.ResponseWriter, r *http.Request) {
	// The signature covers the body as it came: read
	// its bytes. A json.Decoder on r.Body loses them.
	body, err := io.ReadAll(r.Body)
	if err != nil {
		http.Error(w, "unreadable", http.StatusBadRequest)

In the SDK’s tests: run with net/http/httptest.

Domain

Send from your own domain

Your product sends as your own domain either way. What changes is where your team’s mail lives.

  • Sending only. Your team’s mail stays at Google, Microsoft or wherever it is now. Mailset asks for DKIM, a bounce host and DMARC, and leaves your MX alone. Send from a domain whose mail stays elsewhere
  • Mailboxes too. Your team’s mail moves to Mailset, with a real mailbox for every address on the domain and your product’s email on the same bill. Set up a domain
mailset domains add example.com --sendingmailset domains apply example.com --sendingmailset domains check example.commailset keys create --send --domain example.com --from moc.elpmaxe@olleh --name "Acme API"
Facts

What the Go SDK’s build checks

Each line comes from the SDK’s own build, which fails when one stops being true.

FactDetailKnown from
Go 1.22+The oldest its manifest allowsIts manifest
No dependenciesNothing else to install beside itIts manifest
Typed throughoutStructs and typed enums, checked by vetA test
Next

Where to go from here

Pricing

Product email on every plan

  • Base$29a month10 members included
  • Team$79a month25 members included
  • BaseRegular price $29$14.50a month10 members included
  • TeamRegular price $79$39.50a month25 members included

Black Friday prices, for trials started by Thursday, Dec 31. Offer terms

Both include 10,000 emails a month, your product’s and your team’s together. Past that it’s $0.40 per 1,000 with pay as you go.

Every price, and what teams pay elsewhere

Questions

Sending from Go, asked and answered

Can goroutines share one client?

Yes. Make it with NewClient when the server starts and pass it around: it is safe for concurrent use.

Do I need net/smtp?

No. The client sends with net/http to Mailset’s HTTPS API, so there’s no SMTP dialer, TLS setting or password to manage.

Can another router serve the handler?

Any router that mounts an http.HandlerFunc, since hook is one. Keep io.ReadAll ahead of any JSON binding. The POST /hooks/mailset pattern in main is the standard library’s own, new in Go 1.22.

How do I tell a refusal from a network error?

errors.As(err, &refused) with a *mailset.Error catches Mailset’s answers, and refused.Code names each one with a word that never changes. Anything else is the network or your context.

Make a key and sendTry it on your own domain

Make a key in Settings › Developers, keep it as MAILSET_KEY, and run the example above.7 days free, with everything on. Make a key, run the example above and watch the receipt come back.

Open Mailset
Continue with Google

By starting you agree to the Terms and Privacy Policy.