SDKs
An official SDK for each language your server runs, and what every one of them does the same way.
Mailset has an official SDK for each language below. Every one builds the message, signs each request with your key and checks the answer, and has a typed method for every command of the API.
- TypeScriptand JavaScript · Node.js 20+, Bun 1.4+, Deno 2.9+, Cloudflare Workers
- PythonPython 3.9+
- GoGo 1.22+
- RubyRuby 3.0+
- PHPPHP 8.1+
- JavaJava 17+
- RustRust 1.88+
- CLImacOS, Linux
- HTTP APIAny language
Or start from your framework. Each guide runs from install to webhooks.
- Next.jsTypeScript · send and webhooks
- ExpressTypeScript · send and webhooks
- NestJSTypeScript · send and webhooks
- Cloudflare WorkersTypeScript · send and webhooks
- FastAPIPython · send and webhooks
- DjangoPython · send and webhooks
- FlaskPython · send and webhooks
- RailsRuby · send and webhooks
- LaravelPHP · send and webhooks
- SymfonyPHP · send and webhooks
- Spring BootJava · send and webhooks
On this page
What every SDK does the same
The SDKs are written to one contract, so what you learn in one language holds in the next.
- Every public command238 commands, each a typed method
- Retries built inTwo more tries, and a send never doubles
- Timeouts per try30 seconds a try, then tried again
- Idempotency keysA send repeated with its key goes once
- Webhook verificationSignatures checked, every event typed
- Credential checkRefused before sending if your key can’t
Credentials
A client made with no arguments reads MAILSET_KEY from the environment, and MAILSET_TOKEN when there is no key. A key or a token you pass in wins over both: Use it shows the client both ways. Authentication says how to make each.
An app key sends as the mailboxes it was approved for. An API token is a person's, for the commands no app key can run, such as adding a domain. A command the client's credential can't run is refused before any request leaves, with an error that names the credential it needs.
Retries and timeouts
A call that gets no answer, or a 5xx one, is tried again: twice unless you set otherwise, waiting longer each time. A refusal is never tried again, since the same request gets the same answer. One try may take 30 seconds unless you set another limit, for the client or for one call.
A send is safe to try again. It keeps its Message-ID, so Mailset never sends it twice.
Errors
Every refusal is one kind of error, with the same fields in every language: code, which never changes and is what your code branches on, message for people, the HTTP status, and on some codes refusal, retryAt and issues. Each error also carries a link to its code in Errors and limits.
Idempotency
Give a send an idempotencyKey, and sending it again after a timeout or a crash sends nothing new: the same key from the same address answers the first receipt. Retry without sending twice has the rules.
The Mailset-Client header
Every request carries a Mailset-Client header: the SDK's language and version, then the framework, the runtime and the operating system it found. It tells Mailset which SDKs are in use. It names no host, path, user or app.
Mailset keeps the SDK's name and version with each message it sends, and your organization sees them as client on every delivery line of that message.
Versions
Every Mailset SDK ships under the same version number.
Names
A field keeps its name in every SDK, in each language's own case.
| Language | idempotencyKey is written |
|---|---|
| TypeScript | idempotencyKey |
| Python | idempotency_key |
| Go | IdempotencyKey |
| Ruby | idempotency_key |
| PHP | idempotencyKey |
| Java | idempotencyKey |
| Rust | idempotency_key |
A method is named for its command, as domains.add is. Where a language can't spell one, the method gets a name that says what it does.
| Language | Command | Its method | Why |
|---|---|---|---|
| Python | contacts.import | import_contacts | import is a hard keyword in Python: contacts.import(…) doesn’t parse. |
| Python | rules.import | import_rules | import is a hard keyword in Python. |
| Ruby | messages.send | send_message | send is Object#send, which Ruby itself and many libraries call. |
| Java | billing.switch | switchPlan | switch is a Java keyword. |
| Java | addresses.default | setDefault | default is a Java keyword. |
| Java | contacts.import | importContacts | import is a Java keyword. |
| Java | rules.import | importRules | import is a Java keyword. |
Mascots: Duke by Joe Palrang for Sun Microsystems, BSD; the Go gopher by Renée French, CC BY 4.0; Ferris by Karen Rustad Tölva, CC0. Each is simplified here to read at a small size.