Transactional mail
Send receipts, password resets, and other transactional email from your own domain with client.mail in the Oblien SDK or the Mail REST API. Your sending domains, keys, allowances, and delivery history belong to your namespace. You can use Mail without a VM.
This guide covers API v2. Monthly sender and domain cap methods require SDK 4.2.0 or later. Before enabling sending in production, check for mail.send in the live API reference.
Choose a namespace
Use one namespace for each organization that needs its own sending allowance and delivery history. Teammates and applications in that organization can share a verified domain and use separate keys. Adding a teammate does not use another domain slot.
| Caller | Credential and access |
|---|---|
| Your server | Your ordinary account-owner credential with admin scope can activate sending, change allowances, manage billing holds, and close a tenant. Keep this credential on your server. |
| Organization members | Grant mail.read to view usage and delivery history, mail.send to submit messages, or mail.manage to manage domains and keys and inspect suppressions and webhook deliveries. |
| Sending application | Use a send-only key. Scope it to a domain or an exact From address when the app only needs that sender. |
If your application serves multiple organizations, verify the signed-in member’s access on your server. Resolve the namespace from the organization’s stored ID and slug on every request, including requests that contain a message or webhook ID. Keep this mapping when the organization is renamed.
On Enterprise, the account owner sets an independent allowance for each namespace. Other tiers also have account-wide limits for recipients, sending rate, domains, and keys. Account recipient limits use rolling 24-hour and 30-day windows. Every tier uses the owner’s funded wallet and is subject to service sending capacity.
Activate the organization
Run the management examples on your server. Set OBLIEN_CLIENT_ID and OBLIEN_CLIENT_SECRET to your normal account admin credential. Replace mail-acme with your namespace slug. The send example uses a separate application key. The cURL examples use Bash and jq and share the variables defined here.
import Oblien from 'oblien';
const client = new Oblien({
clientId: process.env.OBLIEN_CLIENT_ID!,
clientSecret: process.env.OBLIEN_CLIENT_SECRET!,
});
const namespace = 'mail-acme';
await client.namespaces.ensure({ slug: namespace, name: 'Transactional mail' });
const tenant = await client.mail.tenants.ensure(namespace);POST /v2/namespaces/ensure
X-Client-ID: <service client ID>
X-Client-Secret: <service client secret>
Content-Type: application/json
{"slug":"mail-acme","name":"Transactional mail"}
POST /v2/mail/mail-acme/ensure
X-Client-ID: <service client ID>
X-Client-Secret: <service client secret>api='https://api.oblien.com/v2'
namespace='mail-acme'
mail="$api/mail/$namespace"
auth=(-H "X-Client-ID: $OBLIEN_CLIENT_ID" -H "X-Client-Secret: $OBLIEN_CLIENT_SECRET")
json=(-H 'Content-Type: application/json')
curl --fail-with-body "${auth[@]}" "${json[@]}" "$api/namespaces/ensure" \
-d "$(jq -n --arg slug "$namespace" '{slug:$slug,name:"Transactional mail"}')" &&
curl --fail-with-body "${auth[@]}" -X POST "$mail/ensure"Repeated activation returns the same tenant. Save tenant.id with the organization mapping. The tenant response identifies its namespace by ID. Mail webhook payloads identify the namespace by slug. Save both values so you can match incoming events.
Set the plan allowance
New tenants start with zero allowances. domains and keys limit how many domains and keys the organization can have. daily counts recipients over the last 24 hours, period counts recipients in the billing period, and burst limits recipients per second. Use your plan’s UTC timestamps for periodStart and periodEnd. The sample limits below are illustrative.
async function applyPlan(periodStart: string, periodEnd: string) {
const policy = await client.mail.tenants.getPolicy(namespace);
return client.mail.tenants.updatePolicy(namespace, {
revision: policy.revision,
domains: 2, keys: 5, daily: 500, period: 5000, burst: 10,
periodStart, periodEnd,
});
}GET /v2/mail/{namespace}/policy
PUT /v2/mail/{namespace}/policy
Content-Type: application/json
{
"revision": 1, "domains": 2, "keys": 5, "daily": 500, "period": 5000, "burst": 10,
"periodStart": "2026-11-01T00:00:00Z", "periodEnd": "2026-12-01T00:00:00Z"
}# PERIOD_START and PERIOD_END come from your current plan.
revision=$(curl --fail-with-body "${auth[@]}" "$mail/policy" | jq -er '.data.revision') &&
body=$(jq -n --argjson revision "$revision" --arg start "${PERIOD_START:?}" \
--arg end "${PERIOD_END:?}" '{revision:$revision,domains:2,keys:5,daily:500,
period:5000,burst:10,periodStart:$start,periodEnd:$end}') &&
curl --fail-with-body "${auth[@]}" "${json[@]}" -X PUT "$mail/policy" -d "$body"Use the revision returned by the preceding read. On mail_revision_conflict, reread the policy and compare it with the currently authorized plan before retrying. Keep the period start on mid-cycle changes. At renewal, the old period must have ended and the new period must begin at or after its end. A period can span up to 366 days.
Verify a sending domain
Add the exact domain that appears in your From address. Publish the ownership TXT record returned for your namespace. A pending claim uses one domain slot and expires after 24 hours. To use a custom return path for bounced mail, set returnPath to a dedicated subdomain such as bounce.notify.example.com.
const domain = await client.mail.domains.add(namespace, { domain: 'notify.example.com' });
// Show domain.records to the DNS administrator and save domain.id.POST /v2/mail/{namespace}/domains
Content-Type: application/json
{"domain":"notify.example.com"}domain=$(curl --fail-with-body "${auth[@]}" "${json[@]}" "$mail/domains" \
-d '{"domain":"notify.example.com"}') &&
domain_id=$(jq -er '.data.id' <<<"$domain") &&
jq '.data.records' <<<"$domain"After publishing the TXT record, run Check DNS. Use each returned record’s type, name, value, and status to complete verification. Publish the DKIM CNAME records that authenticate your messages. If you configured a custom return path, publish the returned MX and SPF records on that subdomain. Keep your existing incoming-mail MX records. Mail also rechecks pending domains automatically.
const checked = await client.mail.domains.verify(namespace, domain.id);
const latest = await client.mail.domains.get(namespace, domain.id);POST /v2/mail/{namespace}/domains/{domainId}/verify
GET /v2/mail/{namespace}/domains/{domainId}curl --fail-with-body "${auth[@]}" -X POST "$mail/domains/$domain_id/verify"
curl --fail-with-body "${auth[@]}" "$mail/domains/$domain_id"Enable sending once state is ready. While pending_dns or verifying, show the records and checkedAt. A record with lookup_error means the check could not complete. For verification_failed or disabled, display the returned reason. The domain list returns an ownership summary for each domain. Use the detail endpoint for DNS instructions and readiness.
A verified notify.example.com can send from multiple addresses. Add example.com or alerts.notify.example.com separately if you use them as From domains. Each exact domain has one verified owner. A transfer requires the old owner to release it and the new tenant to publish fresh proof.
Monthly sender and domain caps
Caps use calendar months in UTC. Each recipient in To, Cc and Bcc uses one slot in the month the request was queued. All keys that can send as the same address share its cap, including replacement keys. Address casing shares one counter. A domain cap covers its exact domain across all senders. A send must fit the sender cap, domain cap, namespace allowance, and any account limits. A cap of zero blocks sending. Clearing a cap preserves counts and leaves the other limits in force.
accepted counts recipients accepted for delivery. pending counts queued, in-flight, and uncertain recipients. A confirmed failure releases the reservation. Lowering a cap also affects queued mail when it reaches dispatch. Each page includes monthStart, resetAt, and nextCursor. Each row includes identity and monthlyCap (null for a shared allowance). Pages list identities with caps, registered identities such as address-scoped keys or domains, and identities in retained receipts. Use mail.read to list and mail.manage to change caps.
The page-level unattributed totals cover older receipts whose identity is unavailable. Read them once per namespace and month. Older receipts with a known domain count toward that domain and conservatively toward a configured sender cap on that domain. They are excluded from individual sender counts until attributed.
const sender = '[email protected]';
await client.mail.senders.setCap(namespace, sender, 1000);
await client.mail.domains.setCap(namespace, 'notify.example.com', 5000);
const page = await client.mail.senders.listUsage(namespace, { limit: 50 });
for (const { identity, monthlyCap, accepted, pending } of page.data) {
console.log(identity, monthlyCap, accepted, pending);
}
if (page.nextCursor) {
const next = await client.mail.senders.listUsage(namespace, { cursor: page.nextCursor, limit: 50 });
}
const domains = await client.mail.domains.listUsage(namespace, { limit: 50 });
// Remove only the sender-specific cap.
await client.mail.senders.clearCap(namespace, sender);PUT /v2/mail/{namespace}/caps/sender
Content-Type: application/json
{"sender":"[email protected]","monthlyCap":1000}
PUT /v2/mail/{namespace}/caps/domain
Content-Type: application/json
{"domain":"notify.example.com","monthlyCap":5000}
GET /v2/mail/{namespace}/usage/senders?limit=50
GET /v2/mail/{namespace}/usage/domains?limit=50Send the same PUT with monthlyCap set to null to clear a cap. Pass the returned nextCursor as the URL-encoded cursor query parameter to fetch the next page.
curl --fail-with-body "${auth[@]}" "${json[@]}" -X PUT "$mail/caps/sender" \
-d '{"sender":"[email protected]","monthlyCap":1000}'
curl --fail-with-body "${auth[@]}" "${json[@]}" -X PUT "$mail/caps/domain" \
-d '{"domain":"notify.example.com","monthlyCap":5000}'
curl --fail-with-body "${auth[@]}" "$mail/usage/senders?limit=50"
curl --fail-with-body "${auth[@]}" "$mail/usage/domains?limit=50"Issue a sending key
Use name alone for a tenant-wide key, domainId for a domain-wide key, or sender for an exact address. When both restrictions are supplied, the address must belong to that domain. Reveal the returned secret once to its authorized owner. The key list contains the prefix, scope, and timestamps. Keep the secret out of logs and analytics.
const key = await client.mail.keys.create(namespace, {
name: 'Order receipts',
domainId: domain.id,
sender: '[email protected]',
});POST /v2/mail/{namespace}/keys
Content-Type: application/json
{"name":"Order receipts","domainId":"<domain ID>","sender":"[email protected]"}key=$(curl --fail-with-body "${auth[@]}" "${json[@]}" "$mail/keys" \
-d "$(jq -n --arg id "$domain_id" '{name:"Order receipts",domainId:$id,sender:"[email protected]"}')") &&
OBLIEN_MAIL_KEY=$(jq -er '.data.secret' <<<"$key") &&
key_id=$(jq -er '.data.id' <<<"$key")
unset keySend and retry
Use the application’s send-only key for this request. Supply bare email addresses, a single-line subject, at least one To address, and a text or HTML body. The combined To, Cc, and Bcc limit is 50 recipients. replyTo addresses do not consume sending quota.
import Oblien from 'oblien';
const app = new Oblien({ token: process.env.OBLIEN_MAIL_KEY! });
const receipt = await app.mail.messages.send('mail-acme', {
from: '[email protected]',
to: ['[email protected]'],
subject: 'Order 3921',
text: 'We received your order.',
}, { idempotencyKey: 'order-3921-confirmation' });POST /v2/mail/mail-acme/messages
Authorization: Bearer <mail key>
Content-Type: application/json
Idempotency-Key: order-3921-confirmation
{"from":"[email protected]","to":["[email protected]"],"subject":"Order 3921","text":"We received your order."}curl --fail-with-body https://api.oblien.com/v2/mail/mail-acme/messages \
-H "Authorization: Bearer $OBLIEN_MAIL_KEY" \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: order-3921-confirmation' \
-d '{"from":"[email protected]","to":["[email protected]"],"subject":"Order 3921","text":"We received your order."}'HTTP 202 acknowledges durable acceptance. Store the receipt ID with your application event. The SDK returns the receipt directly. REST wraps it in { success, data }. This is an example receipt at the default price.
{
"success": true,
"data": {
"id": "c5ff183a-b18c-4e78-a28e-3517fd99742f",
"state": "queued",
"recipients": 1,
"credits": { "amount": 0.05, "state": "held" },
"createdAt": "2026-11-20T10:00:00.000Z",
"reason": null
}
}Use one stable idempotency key per logical send within a namespace, using 1–128 visible ASCII characters without spaces. Retry a lost HTTP response with the same key and payload. A changed payload returns HTTP 409. If the receipt shows unknown, acceptance has not yet been confirmed. Keep the receipt and check its events. Submitting the same email with a fresh key can send it twice.
Usage, charges and delivery
The default price is $0.50 per 1,000 recipients accepted for sending (50 Oblien credits). Every To, Cc, and Bcc recipient counts. A message with three recipients uses three units. The receipt shows the quoted amount when Mail queues the message.
credits.state starts as held. It becomes charged when Mail confirms acceptance for sending, or released if the send fails before acceptance. A delivery or bounce does not create a second charge. Older receipts without a recorded price show unpriced. usage.get separates used recipients (used24h, usedPeriod) from reservations (reserved24h, reservedPeriod) and returns both reset times. A send with an unknown outcome keeps its reservation in the original windows.
Use a management credential with mail.read for these reads. Set messageId or message_id to the receipt ID saved by the sending application.
const usage = await client.mail.usage.get(namespace);
const message = await client.mail.messages.get(namespace, messageId);
const events = await client.mail.messages.listEvents(namespace, messageId, { limit: 25 });GET /v2/mail/{namespace}/usage
GET /v2/mail/{namespace}/messages/{messageId}
GET /v2/mail/{namespace}/messages/{messageId}/events?limit=25curl --fail-with-body "${auth[@]}" "$mail/usage"
curl --fail-with-body "${auth[@]}" "$mail/messages/$message_id"
curl --fail-with-body "${auth[@]}" "$mail/messages/$message_id/events?limit=25"The receipt can be queued, dispatching, unknown, accepted, delayed, delivered, bounced, complained, suppressed, or failed. Delivered means the receiving mail server accepted the message. Show each recipient’s event kind, recipient and at for multi-recipient messages. Queued payloads are encrypted, and a message still waiting for dispatch after 24 hours expires. Event and webhook delivery history are retained for 90 days. Receipts with held credits or needed for an active usage period can be retained longer.
List resources in the organization
Use the authorized namespace on every list and detail request. A mail manager can inspect keys and suppressions. Email apps with a send-only credential cannot read these lists.
const domains = await client.mail.domains.list(namespace, { limit: 25 });
const keys = await client.mail.keys.list(namespace, { limit: 25 });
const messages = await client.mail.messages.list(namespace, { limit: 25 });
const suppressions = await client.mail.suppressions.list(namespace, { limit: 25 });GET /v2/mail/{namespace}/domains?limit=25
GET /v2/mail/{namespace}/keys?limit=25
GET /v2/mail/{namespace}/messages?limit=25
GET /v2/mail/{namespace}/suppressions?limit=25curl --fail-with-body "${auth[@]}" "$mail/domains?limit=25"
curl --fail-with-body "${auth[@]}" "$mail/keys?limit=25"
curl --fail-with-body "${auth[@]}" "$mail/messages?limit=25"
curl --fail-with-body "${auth[@]}" "$mail/suppressions?limit=25"List responses have data and nextCursor. Pass that cursor back to the same listing for the same namespace. Stop when it is null. The limit range is 1–100. When constructing a URL, encode the cursor as a query value.
if (messages.nextCursor) {
const nextPage = await client.mail.messages.list(namespace, {
limit: 25, cursor: messages.nextCursor,
});
}GET /v2/mail/{namespace}/messages?limit=25&cursor={urlEncodedCursor}# Use the non-null nextCursor from the previous messages page.
curl --fail-with-body "${auth[@]}" -G "$mail/messages" \
--data-urlencode 'limit=25' --data-urlencode "cursor=$cursor"Webhooks
Register a signed webhook once per organization from your server. Pass the namespace slug, your public HTTPS receiver URL, and a signing secret. Use the shared /v2/webhooks endpoint.
await client.webhooks.create({
namespace,
url: 'https://hooks.example.com/oblien/mail',
secret: process.env.OBLIEN_MAIL_WEBHOOK_SECRET!,
events: [
'mail.delivery', 'mail.bounce', 'mail.complaint', 'mail.suppressed',
'mail.domain.verified', 'mail.tenant.paused', 'mail.quota.threshold',
],
});POST /v2/webhooks
Content-Type: application/json
{
"namespace": "mail-acme",
"url": "https://hooks.example.com/oblien/mail",
"secret": "<webhook signing secret>",
"events": ["mail.delivery","mail.bounce","mail.complaint","mail.suppressed",
"mail.domain.verified","mail.tenant.paused","mail.quota.threshold"]
}jq -n --arg ns "$namespace" --arg secret "${OBLIEN_MAIL_WEBHOOK_SECRET:?}" \
'{namespace:$ns,url:"https://hooks.example.com/oblien/mail",secret:$secret,
events:["mail.delivery","mail.bounce","mail.complaint","mail.suppressed",
"mail.domain.verified","mail.tenant.paused","mail.quota.threshold"]}' |
curl --fail-with-body "${auth[@]}" "${json[@]}" "$api/webhooks" --data-binary @-Verify the hex HMAC-SHA256 of the raw request body against X-Webhook-Signature with a constant-time comparison. The signed JSON includes id, event, timestamp, and data. Check data.namespace (slug) and data.tenantId against the stored organization mapping. For message outcomes, data.messageId and data.recipient identify the receipt and recipient. Durably deduplicate the signed id and persist the event before returning a 2xx. Retries and replays preserve the event ID in the body and in X-Webhook-Id.
Inspect and replay webhook deliveries
The delivery list includes the last 12 attempts for each delivery. To retry a finished delivery, pass the delivery ID from that list. Replay schedules the original event for another attempt.
const deliveries = await client.mail.deliveries.list(namespace, { limit: 25 });
async function replayDelivery(deliveryId: string) {
await client.mail.deliveries.replay(namespace, deliveryId);
}GET /v2/mail/{namespace}/webhook-deliveries?limit=25
POST /v2/mail/{namespace}/webhook-deliveries/{deliveryId}/replaycurl --fail-with-body "${auth[@]}" "$mail/webhook-deliveries?limit=25"
# Run when an operator requests replay of the selected delivery.
curl --fail-with-body "${auth[@]}" -X POST "$mail/webhook-deliveries/${delivery_id:?}/replay"Tenant status, holds and offboarding
Read state, holds, reason, recovery, and capabilities.send to show whether the organization can send. The possible states are provisioning, active, paused, failed, and closed. If sending is paused, follow the recovery action for each hold. You can clear a billing hold with your approved billing credential. For a reputation hold, check the organization’s findings. For a namespace hold, check the namespace status. Clearing one hold leaves the others in effect.
const status = await client.mail.tenants.get(namespace);
const findings = await client.mail.tenants.listFindings(namespace, { limit: 25 });GET /v2/mail/{namespace}
GET /v2/mail/{namespace}/reputation?limit=25curl --fail-with-body "${auth[@]}" "$mail"
curl --fail-with-body "${auth[@]}" "$mail/reputation?limit=25"Apply or clear a billing hold
Record the reason for each action. Use pause when billing requires suspension and resume when billing clears it.
async function pauseForBilling(reason: string) {
return client.mail.tenants.pause(namespace, { hold: 'billing', reason });
}
async function resumeAfterPayment(reason: string) {
return client.mail.tenants.resume(namespace, { hold: 'billing', reason });
}POST /v2/mail/{namespace}/pause
Content-Type: application/json
{"hold":"billing","reason":"Payment overdue"}
POST /v2/mail/{namespace}/resume
Content-Type: application/json
{"hold":"billing","reason":"Payment received"}pause_for_billing() {
curl --fail-with-body "${auth[@]}" "${json[@]}" "$mail/pause" \
-d '{"hold":"billing","reason":"Payment overdue"}'
}
resume_after_payment() {
curl --fail-with-body "${auth[@]}" "${json[@]}" "$mail/resume" \
-d '{"hold":"billing","reason":"Payment received"}'
}Revoke a key, remove a domain, or close the tenant
Revoke a key to stop an application from using it. Remove a domain to block new sends from it and revoke its scoped keys. Closing the tenant permanently disables its domains and revokes all its keys. Closing a tenant requires account-owner access.
async function revokeKey(keyId: string) {
return client.mail.keys.revoke(namespace, keyId);
}
async function removeDomain(domainId: string) {
return client.mail.domains.remove(namespace, domainId);
}
async function closeTenant(reason: string) {
return client.mail.tenants.close(namespace, { reason });
}DELETE /v2/mail/{namespace}/keys/{keyId}
DELETE /v2/mail/{namespace}/domains/{domainId}
POST /v2/mail/{namespace}/close
Content-Type: application/json
{"reason":"Organization closed mail sending"}revoke_key() {
curl --fail-with-body "${auth[@]}" -X DELETE "$mail/keys/${key_id:?}"
}
remove_domain() {
curl --fail-with-body "${auth[@]}" -X DELETE "$mail/domains/${domain_id:?}"
}
close_tenant() {
curl --fail-with-body "${auth[@]}" "${json[@]}" "$mail/close" \
-d '{"reason":"Organization closed mail sending"}'
}SDK and REST reference
All SDK methods below are under client.mail and take the namespace as the first argument. REST paths are relative to /v2/mail/{identifier}. The OpenAPI contract includes payloads, response schemas and permission metadata.
| SDK methods | REST methods and paths |
|---|---|
tenants.ensure, tenants.get | POST /ensure, GET the namespace mail root |
tenants.getPolicy, tenants.updatePolicy | GET and PUT /policy |
tenants.pause, tenants.resume, tenants.close | POST /pause, /resume, /close |
tenants.listFindings | GET /reputation |
domains.add, domains.list, domains.get, domains.verify, domains.remove | POST and GET /domains, GET and DELETE /domains/{id}, POST /domains/{id}/verify |
keys.create, keys.list, keys.revoke | POST and GET /keys, DELETE /keys/{id} |
messages.send, messages.list, messages.get, messages.listEvents | POST and GET /messages, GET /messages/{id}, GET /messages/{id}/events |
senders.setCap, senders.clearCap, senders.listUsage | PUT /caps/sender, GET /usage/senders |
domains.setCap, domains.clearCap, domains.listUsage | PUT /caps/domain, GET /usage/domains |
usage.get, suppressions.list | GET /usage, GET /suppressions |
deliveries.list, deliveries.replay | GET /webhook-deliveries, POST /webhook-deliveries/{id}/replay |
Errors and recovery
| Code | Caller action |
|---|---|
mail_domain_unavailable, mail_domain_unverified | Check ownership and the exact sending domain. Show the DNS records and their statuses. |
invalid_credentials, mail_sender_unauthorized, mail_policy_forbidden | Check key validity, namespace, From address, and the caller's permission. Tenant policy changes require account-owner access. |
mail_tenant_paused, mail_tenant_unavailable | Read the tenant's state, holds, reason and recovery action. |
mail_idempotency_required, mail_idempotency_conflict | Supply a stable key. Recover the original send if the key already belongs to another payload. |
mail_insufficient_credits, mail_credit_quota_exhausted | Fund the owner's wallet or adjust the namespace credit policy. |
mail_quota_exhausted, mail_throttled | Inspect the allowance and usage. Honor the reset time or retry interval when supplied. Domain and key counts require releasing a slot or increasing the plan. |
| HTTP 503 (temporarily unavailable) | Retry after the indicated delay. For a send, reuse the original idempotency key. |
mail_revision_conflict, mail_invalid_period | Refresh the policy revision and check your billing period boundaries before resubmitting the plan. |
mail_not_found | Check the resource ID and the organization’s namespace mapping. |
mail_invalid_address, mail_invalid_content, mail_recipient_limit | Correct the bare addresses, subject, body or recipient count before sending again. |