How it works
Install our official Node.js SDK via npm or yarn to add robust email capabilities from transactional and promotional email sending. Also, manage contacts, templates, and account, and capture all test emails in a dedicated sandbox for safe debugging.
Configuration
Step 1: Create a Mailtrap account and verify your domain.
Step 2: Install Mailtrap package via npm install mailtrap or yarn add mailtrap
Step 3: Send emails; below you’ll find a minimal usage example.
import { MailtrapClient } from "mailtrap";
const mailtrap = new MailtrapClient({
token: process.env.MAILTRAP_API_KEY, // You can create your API key here https://mailtrap.io/api-tokens
});
mailtrap
.send({
from: { name: "Mailtrap Test", email: "sender@example.com" },
to: [{ email: "recipient@example.com" }],
subject: "Hello from Mailtrap Node.js",
text: "Plain text body",
})
.then(console.log)
.catch(console.error);
Check the official SDK documentation for details.
Use cases
- Send transactional and bulk emails with or without templates.
- Manage sending domains.
- Use Email Sandbox to test emails.
- Manage Sandbox messages, inboxes, and projects.
- Manage contacts.
- Manage email templates, suppressions, and accounts.