This page is the JavaScript-focused companion to the broader sending emails guide. Use it when you want practical Node.js examples and implementation patterns for app code and test suites.
Core API call
The primary call shape is:
sendEmail(inboxId: string, sendEmailOptions: SendEmailOptions): Promise<Response>
inboxId: the MailSlurp inbox that sends the message.sendEmailOptions: recipients, content, headers, and delivery options.
Minimum payload
to is the key field most workflows start with:
await mailslurp.sendEmail(inboxId, {
to: ["user@mycompany.com"],
subject: "Welcome",
body: "Your account is ready",
});
Common SendEmailOptions fields
interface SendEmailOptions {
to?: string[];
cc?: string[];
bcc?: string[];
subject?: string;
body?: string;
html?: boolean;
attachments?: string[];
templateVariables?: Record<string, unknown>;
replyTo?: string;
from?: string;
charset?: string;
}
Use named senders where needed:
- Plain:
qa@example.com - Named:
"QA Team" <qa@example.com>
HTML and template variables
Set html: true when sending markup-based email:
await mailslurp.sendEmail(inboxId, {
to: ["user@test.com"],
subject: "Verify your account",
body: "<p>Use code <strong>483921</strong></p>",
html: true,
});
For reusable transactional messages, use template variables:
await mailslurp.sendEmail(inboxId, {
to: ["user@test.com"],
body: "Hello {{name}}",
templateVariables: { name: "Ari" },
});
Attachments in Node.js
Workflow:
- Read file bytes.
- Convert to base64.
- Upload attachment.
- Send using returned attachment IDs.
import { readFileSync } from "fs";
const bytes = readFileSync("./invoice.pdf");
const base64Contents = Buffer.from(bytes).toString("base64");
See base64 uploads for language-specific patterns.
Production-safe sending checklist
- Validate recipient quality before high-volume sends.
- Use queue-backed send flows for retry resilience.
- Add delivery/bounce webhooks for visibility.
- Keep sender identity (SPF/DKIM/DMARC) aligned with your domain policy.
Related:
Next step
If this is part of test automation, move to receive emails in code and add deterministic receive-side assertions.

