@mightymax/mailqueue
v0.1.3
Published
Simple JavaScript client for the LDMax mailqueue API
Maintainers
Readme
@mightymax/mailqueue
@mightymax/mailqueue is a small JavaScript client for the LDMax mailqueue API.
It is built for server-side apps that want to queue email over HTTP instead of talking to SMTP directly.
Installation
npm install @mightymax/mailqueueQuick Start
import { sendMail } from '@mightymax/mailqueue';
await sendMail({
apiUrl: 'https://mailqueue.example.com',
token: process.env.MAILQUEUE_TOKEN!,
to: '[email protected]',
subject: 'Welcome',
text: 'Your account is ready.'
});The final from address is chosen by the mailqueue API based on the bearer token configuration.
Supported Options
token: required bearer token from the mailqueue admin UIto: required recipient email addresssubject: required subjecttext: optional plain-text bodyhtml: optional HTML bodyreplyTo: optional reply-to email addressscheduledAt: optional ISO datetime with offsetmaxAttempts: optional retry count between1and10headers: optional extra string headersapiUrl: optional base URL, defaults toprocess.env.MAILQUEUE_URLorhttp://localhost:5173endpoint: optional API path, defaults to/api/v1/messagestimeoutMs: optional HTTP timeout, defaults to10000fetch: optional customfetchimplementation
At least one of text or html is required.
SvelteKit Example
Environment
MAILQUEUE_URL=https://mailqueue.example.com
MAILQUEUE_TOKEN=mq_xxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxServer helper
import { sendMail } from '@mightymax/mailqueue';
export async function sendContactNotification(input: {
name: string;
email: string;
message: string;
}) {
await sendMail({
token: process.env.MAILQUEUE_TOKEN!,
to: '[email protected]',
subject: `New contact form message from ${input.name}`,
text: [
`Name: ${input.name}`,
`Email: ${input.email}`,
'',
input.message
].join('\n'),
replyTo: input.email,
headers: {
'x-app': 'website'
},
maxAttempts: 3
});
}Server action
import { fail } from '@sveltejs/kit';
import { sendContactNotification } from '$lib/server/mailer';
export const actions = {
default: async ({ request }) => {
const form = await request.formData();
const name = String(form.get('name') ?? '').trim();
const email = String(form.get('email') ?? '').trim();
const message = String(form.get('message') ?? '').trim();
if (!name || !email || !message) {
return fail(400, {
error: 'Please fill in every field.',
values: { name, email, message }
});
}
try {
await sendContactNotification({ name, email, message });
} catch (error) {
return fail(502, {
error: error instanceof Error ? error.message : 'Unable to queue your message right now.',
values: { name, email, message }
});
}
return { success: true };
}
};Scheduled Delivery
import { sendMail } from '@mightymax/mailqueue';
await sendMail({
token: process.env.MAILQUEUE_TOKEN!,
to: '[email protected]',
subject: 'Invoice reminder',
text: 'This will be queued for later delivery.',
scheduledAt: '2026-04-01T09:00:00+02:00',
maxAttempts: 5
});Error Handling
sendMail() throws normal JavaScript errors for:
- missing or invalid input
- API validation failures
- timeouts
- non-2xx HTTP responses
Use regular try/catch in your app.
Publishing
npm publish --access publicLicense
EUROPEAN UNION PUBLIC LICENCE v. 1.2
