I build mailkube, the email API in this walkthrough. The four DNS records it publishes are the same kind any sending provider needs on your domain.
Before a provider can send as your domain, receivers look for four things in that domain's DNS: a DKIM public key, a DMARC policy, an SPF record, and an MX that catches bounces. Pasting a long DKIM key into a DNS panel by hand is the step that's easiest to get wrong. If your DNS is on Cloudflare, mailkube can write all four for you once you approve them on Cloudflare's side, and that's the path this post takes.

The welcome email this tutorial sends, open in Logs. Addresses, the IP and the identifiers are examples.
This tutorial sends your first email from a domain mailkube has never seen. hello@notify.example.com welcomes jordan@example.com, and the Logs view shows the message accepted, handed over and delivered. The DNS records come from one click on Cloudflare, so you never copy a DKIM key by hand.
Prerequisites
- A mailkube account. The Free plan sends 4,000 emails a month (140 a day) from unlimited domains.
- A domain whose DNS is hosted on Cloudflare.
- Python 3.12 or later, or Go 1.23 or later, for the SDK sections. The curl section needs nothing.
Every example uses notify.example.com. Replace it with your own sending domain.
Add the domain
In the dashboard, open the domain switcher and pick Create Domain. Add a subdomain rather than your apex: the docs' own example is mail.yourcompany.com, and a subdomain keeps this traffic apart from whatever your main domain already sends.
The domain starts in onboarding, where sending is refused. Two steps take it to active: verify the domain, then create a credential for it.
Let Auto Setup write the records on Cloudflare
The domain page lists the records to publish, with an Auto Setup button above them. Click it and mailkube sends you to Cloudflare in a new tab.
Cloudflare shows the four records before anything is written:
| Record | Name | What it does |
|---|---|---|
| TXT | kube1._domainkey.notify |
DKIM public key. mailkube generated the pair and keeps the private half. |
| TXT | _dmarc.notify |
DMARC policy p=none, with reports sent to mailkube. Failures get reported, nothing gets rejected. |
| MX | mkube-send.notify |
Return path. Bounces come back here. |
| TXT | mkube-send.notify |
SPF, checked on the return path. |
SPF is checked on mkube-send, the subdomain your mail is actually sent from, so the SPF record on your main domain stays exactly as it is. Adding a second sender usually means editing that record; here you don't. What each of the three records actually proves is a post of its own.
The authorization is one-time and does not let mailkube change your zone later. It adds records and removes none. Click Authorize, and you land back on the domain page while verification runs.
If your DNS lives somewhere else, copy each Host and Value from the domain page into your provider, then click Verify. Verification keeps running in the background if you close the dialog, since propagation can take a few minutes.
Create an API key
Open Credentials, then API keys, and create one. A key is bound to a single verified domain, and its secret is shown once.
Put it in your environment, where both SDKs look for it:
export MAILKUBE_API_KEY='mk_...'
Send your first email with curl
curl -X POST https://api.mailkube.com/mta/v1/emails \
-H "Authorization: Bearer $MAILKUBE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "Acme <hello@notify.example.com>",
"to": "jordan@example.com",
"subject": "Welcome to Acme",
"html": "<h1>Welcome</h1><p>Your account is ready.</p>"
}'
{
"id": "3f9a7c21-5b6e-4d0a-9c8e-2b7f1e4d6a90",
"message_id": "<3f9a7c21-5b6e-4d0a-9c8e-2b7f1e4d6a90@msg.mailkube.com>"
}
A 200 means the message is queued; delivery happens asynchronously. id is mailkube's identifier, the one webhook events carry. message_id is the RFC Message-ID header the recipient's copy will have.
Send it from Python
pip install mailkube
from mailkube import Mailkube
client = Mailkube() # reads MAILKUBE_API_KEY
email = client.emails.send(
from_="Acme <hello@notify.example.com>",
to="jordan@example.com",
subject="Welcome to Acme",
html="<h1>Welcome</h1><p>Your account is ready.</p>",
text="Welcome\n\nYour account is ready.",
)
print(email.id, email.message_id)
The parameter is from_ because from is a Python keyword; the SDK sends it as from. Passing both html and text gives clients that refuse HTML something to show.
Send it from Go
go get github.com/mailkube/mailkube-go
package main
import (
"context"
"errors"
"log"
"github.com/mailkube/mailkube-go"
)
func main() {
client, err := mailkube.New() // reads MAILKUBE_API_KEY
if err != nil {
log.Fatal(err)
}
email, err := client.Emails.Send(context.Background(), mailkube.SendEmailParams{
From: "Acme <hello@notify.example.com>",
To: []string{"jordan@example.com"},
Subject: "Welcome to Acme",
HTML: "<h1>Welcome</h1><p>Your account is ready.</p>",
})
if err != nil {
var apiErr *mailkube.APIError
if errors.As(err, &apiErr) {
log.Fatalf("%s: %s (request %s)", apiErr.ErrorName, apiErr.Message, apiErr.RequestID)
}
log.Fatal(err)
}
log.Println(email.ID, email.MessageID)
}
Build the client once and share it: it is safe across goroutines. Log RequestID on every failure, because it is the value support asks for.
Find it in Logs
Open Logs and click the row. The panel at the top of this post is what you get: Delivered, and API because the message came through the REST API (an SMTP send says SMTP). Auth is your key being checked, Reception is the message accepted for one recipient, and Delivery quotes the receiving server's reply word for word.
Opens and clicks do not show up yet. Open and click tracking are per-domain settings, and both start off.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
403 invalid_api_key |
The key is missing, wrong, or limited to source IPs your machine is not on. mailkube reports every authentication problem under this one name on purpose. | Check the key and its restrictions in Credentials. |
422 from_domain_not_allowed |
The from address is on a domain other than the one the key is bound to, such as hello@example.com with a key for notify.example.com. |
Send from the key's domain, or create a key for the other one. |
400 missing_user_agent |
A bare HTTP client sent no User-Agent. curl and the SDKs always send one. |
Set a User-Agent that names your integration. |
Where to go next
The message is delivered, but your app only knows it was queued. Delivery outcomes arrive as webhook events (email.delivered, email.bounced and the rest), and a receiver that checks their signatures is the next step. Until then, Sending your first email in the docs covers attachments, custom headers and templates.
How did you set up the DNS for your last sending domain: by hand, with Terraform, or through a provider's one-click flow?





Top comments (0)