← barua.tz

Send email from your code

One POST request sends a receipt, an invoice or a one-time code from your own domain. No SMTP, no ports, and no HTML unless you want to write it. Get a key under Settings → API, then your first send is a curl command away.

OpenAPI (JSON) · Authentication and scopes · Sending · Reading emails · Domains · Sub-accounts · Webhooks · Suppressions · Your database · Errors and limits

Your console#

Everything you set up lives in one place: Settings → API. Make a key there, connect the domain you send from and publish its records, register a webhook, create sub-accounts, connect your own database, and see the suppression list and your credits. Every page of this reference assumes you have been there once.

Each endpoint in the reference has a Try it button. Paste your key once and you can send real requests from the page, edit the sample, and read the answer. Sending an email starts in sandbox mode, which checks everything and delivers nothing.

Your first send#

curl https://barua.tz/api/v1/emails \
  -H "Authorization: Bearer barua_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "sales@yourdomain.co.tz",
    "to": "customer@gmail.com",
    "template": { "name": "receipt", "total": "25,000", "paymentMethod": "M-Pesa" }
  }'

The same thing from Node, or anything else with fetch:

await fetch("https://barua.tz/api/v1/emails", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.BARUA_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    from: "sales@yourdomain.co.tz",
    to: "customer@gmail.com",
    template: { name: "receipt", total: "25,000", paymentMethod: "M-Pesa" },
  }),
});

Rules#

  • from must be on a domain your account has verified in your console. A bare address or "Name <address>" both work.
  • to is one address or an array of up to 10.
  • 60 emails per minute per key, and a daily limit shown on your API settings page.
  • Keys belong on servers. Never ship one in an app or a web page. Anyone who can view source can then send as you.
  • Send only to people who gave you their address. Bounces and spam reports are counted per account, and enough of either pauses sending automatically. That is what keeps everyone else's mail out of the spam folder.

Responses#

Success is 200 with { "id": "..." }. Everything else says what to fix:

401 invalid_keyNo key, or a revoked one. Check the Authorization header.
403 domain_not_yoursThe from-domain is not on your account. Connect it first.
403 domain_not_readyDomain found, but its DNS records are not verified yet.
403 suspendedSending is paused on this account. The message says why.
422 invalid_requestThe body failed validation; the message names the field.
429 rate_limitedOver 60 sends in a minute. Back off and retry.
429 quota_exceededDaily limit reached. Resets at midnight UTC.
502 send_failedWe could not hand it to the mail system. Safe to retry.