@vennyx/mila
v0.2.0
Published
Official TypeScript/JavaScript client for the mila REST API
Readme
@vennyx/mila
Official TypeScript/JavaScript client for the mila REST API.
Requirements: Node.js only — attachment encoding relies on
Buffer, so this package will not run in a browser or edge runtime as-is.
Install
npm install @vennyx/milaUsage
import { MilaClient } from '@vennyx/mila';
const client = new MilaClient({ apiKey: process.env.MILA_API_KEY! });
const domains = await client.domains.list();
const mailbox = await client.mailboxes.create(domains[0].id, {
local_part: 'support',
password_method: 'invitation',
password_recovery_email: '[email protected]',
});
await client.emails.send({
from: mailbox.address,
to: ['[email protected]'],
subject: 'Hello from mila',
text: 'Sent via @vennyx/mila.',
attachments: [{ filename: 'invoice.pdf', content: fs.readFileSync('./invoice.pdf') }],
});By default the client talks to https://api.mila.cx. Pass baseUrl to override it.
Error handling
Every non-2xx response throws a MilaApiError:
import { MilaApiError } from '@vennyx/mila';
try {
await client.mailboxes.get(domainId, 'not-a-real-id');
} catch (err) {
if (err instanceof MilaApiError) {
console.error(err.status, err.message);
}
}Resources
domains, mailboxes, aliases, catchall, rewrites,
identities, forwardings, emails.
Adding a domain
The full self-serve lifecycle (admin-role API key required):
const domain = await client.domains.create({ name: 'example.com' }); // state: "pending"
const records = await client.domains.dnsRecords(domain.id); // what to publish, incl. the verification TXT
const checks = await client.domains.diagnostics(domain.id); // live expected-vs-found DNS check
if (checks.verification.ok && checks.mx.ok) {
await client.domains.activate(domain.id); // server re-checks DNS itself; 422 with the failing blocks otherwise
}