Go Transactional Email API (2026): Send App Mail with net/http and POST /emails
How to send transactional email from Go with Rovela’s HTTP Email API: a net/http helper, environment configuration for the Bearer key, Idempotency-Key, and why net/smtp over mailbox SMTP is the wrong default for app volume. Not an OTP tutorial.
Go already speaks HTTP; transactional email should too
A Go service already posts JSON, talks to payment providers, and runs workers. The natural way to send transactional email — an invoice that is ready, a “your export can be downloaded” note, a shipping update, a security alert — is the same pattern: one HTTPS POST with a Bearer key, not an SMTP session hidden behind net/smtp.
Rovela’s Email API is built for that. There is no official SDK and no module you have to pin. The base URL is https://api.rovela.dev. You authenticate with Authorization: Bearer re_… (Authentication) and queue a message with POST /emails. The response is a message id. HTTP 200 means the message was accepted and queued, not that it has already arrived (Quick Start).
This is not a redo of a Go OTP tutorial, and it is not a language-tour rewrite. If you need one-time codes, start from the existing Go OTP guide and the official verification code example. If you only wanted a first request in Go syntax, the send email in Go tour is already published. This article is everyday Go app mail: a small package in your module, environment variables for the key, an Idempotency-Key on anything a retry might repeat, and documented error handling around the {statusCode, name, message} envelope.
If you are still choosing between HTTP and SMTP, read Email API vs SMTP. Rovela’s SMTP is mailbox SMTP for mail apps (mx.rovela.dev:465, a device credential, send-as-self, 30 messages a minute from one client address). Programmatic volume from a Go process belongs on POST /emails.
What you need before the first Go send
The first-email guide and the Quick Start are the same five steps, whether your caller is curl or net/http:
- Create an account. You start on the free plan, which sends real mail. There is no separate sandbox or test key.
- Add and verify a sending domain (a subdomain such as
mail.example.comis a common choice). You cannot send from a domain you have not verified; an unverified or foreignfromis refused with a 400 that names the domain. See the domain setup guide and what domain email is. - Create an API key. A
sending_accesskey can send and nothing else — the right default for production. Afull_accesskey can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once. - Send with
POST /emails. - Confirm delivery in the dashboard, with
GET /emails/:idorGET /emails/:id/events(those reads needfull_accessor a dashboard session), or with a webhook.
from is a string in the documented form "Acme <hello@yourdomain.com>". The address must sit on a verified sending domain. That is the same rule that makes domain email trustworthy: you prove you control the domain before you speak as it. How the display name and the address work is covered in the From name guide.
At least one of html, text, or template is required. Send both html and text where you can — many clients preview the text part (HTML email API).
A net/http helper in your module
Keep the key on the server. Never put a Rovela key in a browser bundle, a mobile app, or a public repository. A leaked sending_access key can send mail as your domain. Environment variables read at process start (or a small config struct you already use) are the right place in a Go service.
This helper uses the Go standard library so the module does not need a second HTTP client just to send mail. If you already depend on a different client elsewhere in the same codebase, the JSON body and headers are identical.
// emails/client.go
package emails
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"time"
)
type Client struct {
BaseURL string
APIKey string
From string
HTTPClient *http.Client
}
type APIError struct {
StatusCode int `json:"statusCode"`
Name string `json:"name"`
Message string `json:"message"`
}
func (e *APIError) Error() string {
if e.Message != "" {
return e.Message
}
return fmt.Sprintf("rovela: HTTP %d", e.StatusCode)
}
type SendInput struct {
To string
Subject string
HTML string
Text string
ReplyTo string
Tags any
IdempotencyKey string
}
type SendResult struct {
Object string `json:"object"`
ID string `json:"id"`
}
func NewFromEnv() *Client {
base := os.Getenv("ROVELA_BASE_URL")
if base == "" {
base = "https://api.rovela.dev"
}
return &Client{
BaseURL: base,
APIKey: os.Getenv("ROVELA_API_KEY"), // sending_access
From: getenv("ROVELA_FROM", "Acme <hello@mail.acme.com>"),
HTTPClient: &http.Client{
Timeout: 30 * time.Second,
},
}
}
func getenv(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}
func (c *Client) Send(in SendInput) (*SendResult, error) {
payload := map[string]any{
"from": c.From,
"to": in.To,
"subject": in.Subject,
"html": in.HTML,
"text": in.Text,
}
if in.ReplyTo != "" {
payload["reply_to"] = in.ReplyTo
}
if in.Tags != nil {
payload["tags"] = in.Tags
}
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, c.BaseURL+"/emails", bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+c.APIKey)
req.Header.Set("Content-Type", "application/json")
if in.IdempotencyKey != "" {
req.Header.Set("Idempotency-Key", in.IdempotencyKey)
}
resp, err := c.HTTPClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
raw, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
var apiErr APIError
_ = json.Unmarshal(raw, &apiErr)
apiErr.StatusCode = resp.StatusCode
return nil, &apiErr
}
var out SendResult
if err := json.Unmarshal(raw, &out); err != nil {
return nil, err
}
return &out, nil
}
The documented success body is {"object": "email", "id": "9f1c2e40-..."}. Store that id on the order, invoice, or export job. Do not invent other response fields.
The same request in curl, which is useful when you are checking the domain and the key before you wire the helper:
curl -X POST https://api.rovela.dev/emails \
-H "Authorization: Bearer re_your_api_key" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: invoice-ready-inv_1042" \
-d '{
"from": "Acme <hello@mail.acme.com>",
"to": "alice@example.com",
"subject": "Your invoice is ready",
"html": "<p>Invoice INV-1042 is ready to download.</p>",
"text": "Invoice INV-1042 is ready to download."
}'
A handler that sends after a user action
Call the helper after the work that matters has already succeeded — the invoice row is persisted, the export file is in object storage, the shipment is marked dispatched. Put the send on a queue or a background goroutine if the HTTP handler should return quickly, and reuse the same Idempotency-Key whenever that job is retried. The header may be up to 256 characters and is remembered for 24 hours (Idempotency-Key).
// invoice is already saved; notify the customer once.
func notifyInvoiceReady(c *emails.Client, inv Invoice) (*emails.SendResult, error) {
return c.Send(emails.SendInput{
To: inv.CustomerEmail,
Subject: "Your invoice is ready",
HTML: "<p>Invoice " + inv.Number + " is ready to download.</p>",
Text: "Invoice " + inv.Number + " is ready to download.",
ReplyTo: "billing@mail.acme.com",
Tags: map[string]string{
"kind": "invoice_ready",
"invoiceId": inv.Number,
},
IdempotencyKey: "invoice-ready-" + inv.Number,
})
}
tags are optional labels returned with the message; they are not a substitute for Idempotency-Key and they are not topic_id. The Email API tags guide covers the documented shapes. reply_to is the right field when a human should be able to answer; see Email API reply-to. Recipients across to, cc, and bcc are capped at 50, and quota is charged per recipient (cc and bcc).
Do not invent a sandbox. Free-plan keys send real mail. During development, use a verified staging subdomain and recipients you control (how to test a transactional email API).
Errors you should handle in the helper
Every error uses the same shape (Quick Start, Email API error handling):
{
"statusCode": 400,
"name": "Bad Request",
"message": "html or text body is required"
}
Documented cases you will actually hit from a Go service:
- 400 — a missing required field, an unverified or foreign
fromdomain, a template that does not exist, a base64 attachment that does not decode, or more than 50 recipients acrossto,cc, andbcc. - 401 — missing or invalid key, or a
sending_accesskey used to read, reschedule, or cancel a message. Reading events is afull_access(or session) operation. - 429 — rate limit exceeded. Each entry in a batch counts individually, so a large batch can trip this partway through.
Surface the message field in your own logs as-is. Do not invent a /logs API; delivery history lives in the dashboard and, with a full_access key, on GET /emails/:id and GET /emails/:id/events.
A 403 can appear on management endpoints when the credential is valid but lacks permission — for example, a sending_access key used against the Domains API. That is a different failure from a 401, and it is documented on the authentication pages. See Email API authentication and the sending domains API guide in this batch.
Delivery is asynchronous — do not poll from the request path
A 200 from POST /emails is not a delivery receipt. Confirm later:
- The Emails view in the dashboard.
GET /emails/:idandGET /emails/:id/eventswith afull_accesskey. You are looking for accepted, delivered, or bounced events on that message (Email delivery status API).- A webhook for anything in production. Verify the HMAC-SHA256 signature (webhook security). Event types include sent, delivered, delayed, bounced, complained, opened, and clicked.
Do not turn a Go handler into a polling loop against /emails/:id/events. The docs are explicit: the events endpoint is useful for debugging a single message; systematic handling belongs on a webhook.
POST /emails/batch accepts up to 100 messages, each with the same schema, processed independently. template and topic_id are rejected on the batch endpoint rather than ignored — send those through POST /emails. If you schedule with scheduled_at, reading, rescheduling, and cancelling need full_access or a dashboard session; a sending_access key can only send. The dedicated scheduled email and batch transactional email guides cover those flows in full; this article will not redo them.
Templates are available if you would rather store HTML in Rovela and send { id, variables } (Templates API, templates guide). template is mutually exclusive with html and text. You can also render HTML in Go (html/template) and pass the resulting strings as html and text — that is ordinary Go, not a Rovela SDK.
What not to do in a Go codebase
Do not point net/smtp or a third-party SMTP package at mx.rovela.dev and send application volume that way. That path is for mailboxes and mail apps. A mailbox can send only as its own address, and the documented client limit is 30 messages a minute. You also lose the HTTP API’s tracking, logs, and webhooks (SMTP, Email API vs SMTP relay).
Do not create a “Rovela SDK” wrapper that invents endpoints, official clients, numeric HTTP rate (req/s) figures, a sandbox flag, or a dedicated IP. Call the documented HTTP API with net/http.
Do not put the key in query parameters, in frontend code, or in a committed file that ships to git. Create a sending_access key for the Go service. If you send for several customers from one organization, a key can be restricted to a single domain (Authentication, Email API for multi-tenant SaaS).
Do not treat a fire-and-forget goroutine as a substitute for idempotency. A background call that retries after a timeout still needs an Idempotency-Key. A background call also does not confirm delivery; only the events API or a webhook does. For retry policy around timeouts and 429s, see Email API retries.
A compact Go checklist
- Verify the sending domain before any production
from. - Store a
sending_accesskey in the environment; constructAuthorization: Bearer …in server-side code. - Send both
htmlandtext. Setreply_towhen a human should be able to answer. - Put an
Idempotency-Keyon any send a queue, payment webhook, or double submit might repeat. - Handle 400, 401, and 429 from the documented error envelope. Remember that 200 means queued.
- Store the returned message
idon the invoice or export job. - Subscribe to webhooks for delivery, bounces, and complaints; use
GET /emails/:id/eventsonly to debug a single message. - Leave mailbox SMTP to people and mail apps.
Once that helper is in place, every other Go handler can call it the same way — receipts, security alerts, “your export is ready” notes — without growing a second email stack. That is the point of a transactional email API: one authenticated HTTP call from the service you already run. For a first request without Go at all, the curl sending guide and HTTP email API pages are the shortest path.