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.
You need to be an admin of your organisation on Barua and able to edit your domain’s DNS. No account yet? Create a free account.
Quick start
#- Accept the sending agreement in your API console (Settings → API → Sending agreement). One time, by an admin.
- Create an API key in the same place, and copy it while it is on screen.
- Add the domain you send from and publish its records (see Domains). Sending waits for the Ownership record.
- Paste the key you copied from Settings → API into your terminal, in place of
barua_...:bashexport BARUA_API_KEY=barua_... - Send a test with the request below.
Your first send
#bashcurl https://barua.tz/api/v1/emails \-H "Authorization: Bearer $BARUA_API_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" },"sandbox": true}'
The same thing from Node, or anything else with fetch:
javascriptawait 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" },sandbox: true,}),});
sandbox runs every check and delivers nothing, so a test costs no credit. Remove it to deliver for real.
Your API console
#Everything you set up lives in one place: your API console, under 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.
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.
Rules
#frommust be on a domain your account has verified in your API console. A bare address or"Name <address>"both work.tois one address or an array of up to 10.- 60 requests a minute per key (600 per account), on any endpoint, and a daily limit shown in your API console.
- 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_limitedMore than 60 requests a minute on one key, or 600 on the account. Back off and retry.429 quota_exceededDaily limit reached. It resets at 03:00 East Africa Time (midnight UTC).502 send_failedWe could not hand it to the mail system. Safe to retry.