Send email from your code
One POST request sends an OTP or a welcome email from your own domain. No SMTP, no ports, no HTML unless you want to write it. Get a key under Settings → API, then the first send is a curl command away.
Send an OTP
The code goes in the subject line, so it is readable from the phone's notification banner without opening anything.
curl https://barua.tz/api/v1/emails \
-H "Authorization: Bearer barua_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "verify@yourdomain.co.tz",
"to": "customer@gmail.com",
"template": { "name": "otp", "code": "482913", "app": "MyShop", "expiresMinutes": 10 }
}'The same thing from Node, or any runtime 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: "verify@yourdomain.co.tz",
to: "customer@gmail.com",
template: { name: "otp", code: "482913", app: "MyShop" },
}),
});Send a welcome email
{
"from": "hello@yourdomain.co.tz",
"to": "customer@gmail.com",
"template": {
"name": "welcome",
"app": "MyShop",
"userName": "Neema",
"message": "Your shop is ready. Add your first product and you are live.",
"actionUrl": "https://myshop.co.tz/start",
"actionLabel": "Open my shop"
}
}Every field except name is optional — a bare { "name": "welcome", "app": "MyShop" } already sends something decent.
Send anything else
Skip template and provide the message yourself. Give html, text, or both; whichever you leave out is derived from the other.
{
"from": "Receipts <billing@yourdomain.co.tz>",
"to": ["customer@gmail.com"],
"subject": "Receipt #1042",
"text": "Asante! We received TZS 25,000 for order #1042."
}Rules
frommust be on a domain your account has verified under Settings → Domains. A bare address or"Name <address>"both work.tois one address or an array of up to 10.- 60 emails per minute per key. Enough for OTPs; talk to us before campaigns.
- Keys belong on servers. Never ship one in an app or a page — anyone who can view source can send as you.
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.422 invalid_requestThe body failed validation; the message names the field.429 rate_limitedOver 60 sends in a minute. Back off and retry.502 send_failedWe could not hand it to the mail system. Safe to retry.