Skip to content
Mailcycle
Get started
Go email SDK

The Go email SDK: receive, read and send mail from Go.

Receive email in Go without standing up a mail server. Create an address, block until the next message arrives, read its text, HTML and attachments, and reply in the thread. Mail is stored encrypted and decrypted by your Go binary, with plain structs and errors you can switch on.

Install the Go module
go get mailcycle.email/go

mailcycle.email/go on the Go module proxy · Go 1.26 or later · Apache 2.0 · Free tier, no card

Quickstart

Receive and send email in Go.

Sign in, create an address, wait for a message and answer it. That is the whole loop, and it is the same loop whether the mail is a sign-up code, a customer or a receipt.

  1. 1Install mailcycle.email/go and set MAILCYCLE_PHRASE to your account's recovery phrase.
  2. 2Create an address with mc.Addresses().Create(). It receives mail straight away.
  3. 3Wait for the next message with mc.Messages().WaitFor(), or take it from a webhook.
  4. 4Reply with mc.Messages().Send(), threaded under the original.
The full Go guide
Go: create an address, wait for mail, reply
import (
    "fmt"
    "os"

    "mailcycle.email/go" // package mailcycle
)

mc, err := mailcycle.SignIn(os.Getenv("MAILCYCLE_PHRASE"), mailcycle.Options{})

// A new address that receives mail, sealed to your key.
address, err := mc.Addresses().Create(mailcycle.NewAddress{
    Prefix: "signup",
    Label:  "Test run 42",
})
fmt.Println(address.EmailAddress) // signup-x7k2@...

// Wait for the verification email, decrypted here.
message, err := mc.Messages().WaitFor(mailcycle.WaitOptions{
    AddressID: address.ID,
    Subject:   "verification",
})
fmt.Println(message.Subject, message.Text)

// Reply in the same thread.
_, err = mc.Messages().Send(mailcycle.Outgoing{
    From:      address.EmailAddress,
    To:        message.ReplyTo,
    Subject:   "Re: " + message.Subject,
    Text:      "Thanks, confirmed.",
    InReplyTo: &message,
})
What it does

The whole email API, from Go.

Everything the Mailcycle console can do is in the module: addresses, inbound mail, sending, webhooks, events, API keys and devices.

Create email addresses from Go

mc.Addresses().Create() mints a new address on a shared domain, or on your own domain from Scale, and it receives mail at once. Give it a prefix and a label sealed on your machine.

Receive email and wait for it

mc.Messages().WaitFor() listens on the event stream and returns the next matching message, filtered by sender or subject, opened and ready to read. Without a stream it checks every five seconds.

Read and parse incoming email

mc.Messages().All() and .Attachment() return the sender, subject, plain text, the original HTML, a safe HTML with remote images and trackers removed, and every attachment as bytes.

Send email and reply in the thread

mc.Messages().Send() sends from an address your account owns, with up to ten files. Pass the message you are answering and the threading headers are filled in.

Inbound email webhooks

Register a URL and every message.received event is POSTed to it, signed with HMAC-SHA256 and retried. mailcycle.VerifyWebhookSignature() checks the signature in one line.

A live event stream

mc.Events().Stream() carries the same events over a WebSocket the moment they happen, and reconnects after a drop. Events carry ids, never content.

Email testing

Test email verification in go test, chromedp and Playwright for Go.

Create an address at the top of a test, drive the sign-up flow, then call WaitFor and read the code from message.Text. A timeout comes back as an *APIError with Code "timeout", so t.Fatal gets a real reason. Delete the address with t.Cleanup.

  • A real address on a real domain, so the mail goes through the same path your users' does.
  • One call blocks until the message lands, filtered by subject or sender, with a timeout you set.
  • Text, HTML and attachments come back parsed, so pulling out a code or a link is a regular expression.
  • Mail received from the moment you start waiting counts, even if it lands before the stream is up.
Inbound email webhooks

Handle incoming email in net/http, Gin, Echo and Chi.

Rather than polling, let the mail come to you. A webhook POSTs each event to your URL the moment it happens, signed so you can prove it came from Mailcycle, and retried if your server is down.

Events carry ids, never content. Fetch the message by id and it is opened in your code, exactly as it would be otherwise. Webhooks are on Operator and above.

Webhooks in the docs
net/http: verify a webhook, then fetch the message
http.HandleFunc("POST /hooks/mailcycle", func(w http.ResponseWriter, r *http.Request) {
    raw, _ := io.ReadAll(r.Body) // the body exactly as it arrived
    if !mailcycle.VerifyWebhookSignature(secret, raw, r.Header.Get("Mailcycle-Signature")) {
        http.Error(w, "bad signature", http.StatusUnauthorized)
        return
    }

    var event struct {
        Type    string `json:"type"`
        Payload struct {
            MessageID string `json:"messageId"`
        } `json:"payload"`
    }
    json.Unmarshal(raw, &event)
    if event.Type == "message.received" {
        message, err := mc.Messages().Get(event.Payload.MessageID)
        if err == nil {
            handle(message.Subject, message.Text)
        }
    }
    w.WriteHeader(http.StatusNoContent)
})
No mail server

Instead of net/smtp and an IMAP library.

Go's net/smtp package is frozen and only sends, through a server you supply. There is no IMAP in the standard library, so receiving means a third-party IMAP client, a mailbox and its password, or an SMTP server of your own and a MIME parser.

Here both directions are HTTPS calls. An address is a struct literal, a message arrives on a webhook or through one blocking WaitFor, and it comes back as a parsed Message with Text, SafeHTML and attachments as []byte.

It is not a bulk sender. If you need newsletters or high volumes of transactional mail, use a sending service for that; Mailcycle is for addresses your code owns and the mail that comes back to them.

End-to-end encrypted

Mail is opened in your Go code, not on our servers.

Each address has a key pair derived from your recovery phrase. Incoming mail is sealed to its public key before anything is written down, and the module derives the private key on your machine to open it.

How the encryption works
  • Signing in proves you hold the key by answering a challenge, so the phrase never crosses the wire.
  • Bodies, attachments, address labels and API key names are all sealed. The server stores ciphertext.
  • Mail sealed by one SDK opens in every other, and in the app, because they share one published format.
  • The module is checked against Mailcycle's published test vectors, including the cases that must be refused.
  • Because the server cannot read mail, there is no server-side search. Search runs where the mail is opened.
Use cases

What developers build with the Go SDK.

It runs in HTTP services, background workers, Kubernetes jobs and command-line tools: anywhere Go code needs an email address of its own.

End-to-end tests for sign-up and login

Verification emails, one-time passcodes, magic links, password resets and invitations, checked by a real test in go test, chromedp and Playwright for Go.

A support or orders inbox your code answers

Give an address to a queue, read what customers send, and reply from the address they wrote to, threaded under their message.

Receipts, invoices and alerts as data

Point suppliers, monitoring and other services at an address and pull the text and attachments straight into your own records.

An address per customer, job or device

Mint addresses on demand and keep each stream of mail separate, with its own label, and delete one when the job is done.

Building an AI agent? It can have an inbox too, through the Mailcycle MCP server, without writing any Go at all.

The package

Go SDK at a glance.

Maintained by Mailcycle, the team that runs the API.

The Mailcycle Go SDK at a glance
Packagemailcycle.email/go
Registrythe Go module proxy
Install withgo get
NeedsGo 1.26 or later
AlsoImported as package mailcycle.
LicenceApache 2.0, free to use in your own applications
APIJSON over HTTPS at api.mailcycle.email
GuideThe Go guide in the docs

What each plan unlocks. Free receives mail. A signed-in session sends from Personal up. API keys and webhooks start at Operator, and sending from an API key at Scale. See pricing.

Questions

Go email SDK questions.

Run go get mailcycle.email/go, sign in with mailcycle.SignIn, and create an address with mc.Addresses().Create(). Mail sent to it is stored encrypted, and mc.Messages().All() or mc.Messages().WaitFor() returns it decrypted, parsed into a Message struct. No mail server, no IMAP.

Call mc.Messages().Send(mailcycle.Outgoing{From, To, Subject, Text}) with an address your account owns. Set InReplyTo to the message you are answering and the threading headers are filled in. Sending from a signed-in session works from the Personal plan, and from an API key on Scale and above.

Go 1.26 or later. The module path is mailcycle.email/go and the package name is mailcycle.

The module is free and open source under the Apache 2.0 licence. The Mailcycle Free plan costs nothing and needs no card: 3 email addresses and 3,000 messages received a month, receive only. Sending starts on Personal at $7 a month, API keys and webhooks on Operator at $15, and sending from an API key on Scale at $19.

No. Incoming mail is sealed to the address's public key before it is stored, and the private key is derived from your recovery phrase inside your Go process. The server holds ciphertext it cannot open. Mail you send leaves in plain text so the recipient's server can read it, and the copy kept in Sent is sealed like the rest.

Call mc.Addresses().Create() at the start of the run and delete the address at the end, which frees its place on your plan. Each address receives mail as soon as it exists. This is for testing your own product and for mail meant for you: registering accounts on other services in bulk, or against their terms, breaks the Acceptable Use Policy.

No. Mailcycle is inbound email infrastructure, and sending is there to answer what arrives. Sending is capped at 60 messages an hour per account and 20 an hour per device or agent, with a daily limit set by the plan, and the Acceptable Use Policy rules out bulk, marketing and outreach mail.

The API is plain JSON over HTTPS at api.mailcycle.email, so anything can call it. Message content comes back encrypted, though, and the module is what derives the keys and opens it. Without an SDK you would implement the published encryption format yourself.

Give your Go code an email address.

Create an account, create an address, and read what arrives. The free tier needs no card.