Sending Transactional Email with TypeScript
A typed, async guide to sending transactional email from Node and TypeScript with the Digitel Africa Mail SDK — install, send, attach and handle errors.
The Digitel Africa Mail TypeScript SDK gives you fully typed requests and responses, so your editor autocompletes every field and the compiler catches mistakes before they ship.
Fully typed from send() to the response — no guessing at field names.
Install the SDK
The SDK targets Node.js 18+ and ships its own type definitions.
npm install @digitel/sdkAuthenticate
Instantiate the client with your API key from process.env. Keep it server-side — never expose a live key in browser code.
import { Digitel } from "@digitel/sdk";
const digitel = new Digitel({ apiKey: process.env.DIGITEL_API_KEY! });Send your first email
Every send is a promise, so await it. The response is typed as an email message.
const message = await digitel.email.messages.send({
from: "[email protected]",
to: ["[email protected]"],
subject: "Your order is confirmed",
html: "<h1>Thanks for your order</h1>",
});
console.log(message.id);Read the response
The returned object is fully typed — message.id, message.status and the rest are all autocompleted.
{
"id": "msg_01HZY8QK3P4RN2",
"object": "email.message",
"status": "queued",
"to": ["[email protected]"],
"created_at": "2026-08-21T09:15:42Z"
}Attach files and send HTML
Attachments take a filename and base64 content. Render your HTML with any template library.
const message = await digitel.email.messages.send({
from: "[email protected]",
to: ["[email protected]"],
subject: "Your invoice",
html: renderedHtml,
attachments: [{ filename: "invoice.pdf", content: pdfBase64 }],
});Handle errors
Narrow caught errors to ApiError for typed access to the message and request id.
import { ApiError } from "@digitel/sdk";
try {
await digitel.email.messages.send(payload);
} catch (err) {
if (err instanceof ApiError) {
console.error(`Send failed: ${err.message} (${err.requestId})`);
}
}Types are the cheapest tests you will ever write. Let the compiler check your email payloads so production never sees a typo.
Ready for more? The docs cover batching, scheduling and delivery webhooks.