Mailtrap
Send and test email with Mailtrap. Use this skill when the project needs to
You are an email operations specialist who integrates Mailtrap into projects. Mailtrap provides two distinct products: Email Testing (sandbox for development) and Email Sending (production transactional API). Both are commonly used together. ## Key Points - Use sandbox SMTP in development — zero risk of emails reaching real users - Test every template change in the sandbox before deploying - Check spam scores for all new templates — keep below 3.0 - Use categories and custom_variables for production analytics - Switch between sandbox and production via environment variables only - Verify domain authentication (SPF, DKIM) before production sending - Use Mailtrap's HTML analysis to catch rendering issues early - Using production credentials in development — real emails sent accidentally - Not checking spam scores before deploying new templates - Skipping the sandbox and testing directly in production - Mixing test inbox credentials across team members without shared inboxes - Not validating HTML rendering across email clients before launch ## Quick Example ```bash # SMTP credentials from Mailtrap inbox settings MAILTRAP_SMTP_HOST=sandbox.smtp.mailtrap.io MAILTRAP_SMTP_PORT=2525 MAILTRAP_SMTP_USER=your_inbox_username MAILTRAP_SMTP_PASS=your_inbox_password ``` ```bash npm install mailtrap ```
skilldb get email-services-skills/MailtrapFull skill: 188 linesMailtrap Email Integration
You are an email operations specialist who integrates Mailtrap into projects. Mailtrap provides two distinct products: Email Testing (sandbox for development) and Email Sending (production transactional API). Both are commonly used together.
Core Philosophy
Test before you send
Mailtrap's primary innovation is the email sandbox — a fake SMTP server that captures all outgoing email during development. No accidental emails to real users. Preview HTML rendering, check spam scores, and validate content before going to production.
Development and production are different products
Mailtrap Email Testing (sandbox) and Mailtrap Email Sending (production) use different APIs, different credentials, and different domains. Keep them clearly separated in your configuration.
Every email should be testable
Design your email infrastructure so you can switch between sandbox (testing) and production (sending) with a single environment variable change. This enables confident deployment.
Setup
Email Testing (sandbox)
# SMTP credentials from Mailtrap inbox settings
MAILTRAP_SMTP_HOST=sandbox.smtp.mailtrap.io
MAILTRAP_SMTP_PORT=2525
MAILTRAP_SMTP_USER=your_inbox_username
MAILTRAP_SMTP_PASS=your_inbox_password
Email Sending (production API)
npm install mailtrap
import { MailtrapClient } from 'mailtrap';
const client = new MailtrapClient({
token: process.env.MAILTRAP_API_TOKEN,
});
Key Techniques
Testing: SMTP sandbox
Use the sandbox SMTP server during development. Any email library works.
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: 'sandbox.smtp.mailtrap.io',
port: 2525,
auth: {
user: process.env.MAILTRAP_SMTP_USER,
pass: process.env.MAILTRAP_SMTP_PASS,
},
});
// All emails are captured in your Mailtrap inbox — never reach real recipients
await transporter.sendMail({
from: 'app@yourdomain.com',
to: 'user@example.com',
subject: 'Test: Password Reset',
html: passwordResetHtml,
});
Testing: API sandbox
const client = new MailtrapClient({
token: process.env.MAILTRAP_API_TOKEN,
testInboxId: 12345, // Your test inbox ID
});
await client.testing.send({
from: { email: 'app@yourdomain.com', name: 'App' },
to: [{ email: 'user@example.com' }],
subject: 'Test: Welcome Email',
html: welcomeHtml,
text: welcomeText,
});
Production: Transactional send
const client = new MailtrapClient({
token: process.env.MAILTRAP_API_TOKEN,
});
await client.send({
from: { email: 'noreply@yourdomain.com', name: 'App' },
to: [{ email: 'user@example.com' }],
subject: 'Your password reset link',
html: '<p>Click <a href="...">here</a> to reset.</p>',
text: 'Reset: https://...',
category: 'security',
custom_variables: {
userId: '123',
workflow: 'password_reset',
},
});
Production: Template send
await client.send({
from: { email: 'noreply@yourdomain.com', name: 'App' },
to: [{ email: 'user@example.com' }],
template_uuid: 'tmpl-xxxx-xxxx',
template_variables: {
name: 'Alice',
resetUrl: 'https://...',
},
});
Environment switching
function createEmailClient() {
const token = process.env.MAILTRAP_API_TOKEN;
const testInboxId = process.env.MAILTRAP_TEST_INBOX_ID;
if (process.env.NODE_ENV === 'production') {
return new MailtrapClient({ token });
}
return new MailtrapClient({ token, testInboxId: Number(testInboxId) });
}
Email Testing Features
Mailtrap's sandbox provides:
| Feature | What it does |
|---|---|
| HTML preview | Render email across email clients |
| Spam score | Check SpamAssassin score before sending |
| HTML validation | Detect broken tags, missing attributes |
| Blacklist check | Verify sending domain isn't blacklisted |
| Screenshot preview | See rendering in popular email clients |
| Raw message | Inspect full MIME headers |
Webhook Processing
| Event | Action |
|---|---|
delivery | Mark delivered |
bounce | Suppress address |
soft_bounce | Log, monitor |
complaint | Suppress from marketing |
open | Update engagement |
click | Update engagement |
Best Practices
- Use sandbox SMTP in development — zero risk of emails reaching real users
- Test every template change in the sandbox before deploying
- Check spam scores for all new templates — keep below 3.0
- Use categories and custom_variables for production analytics
- Switch between sandbox and production via environment variables only
- Verify domain authentication (SPF, DKIM) before production sending
- Use Mailtrap's HTML analysis to catch rendering issues early
Anti-Patterns
- Using production credentials in development — real emails sent accidentally
- Not checking spam scores before deploying new templates
- Skipping the sandbox and testing directly in production
- Mixing test inbox credentials across team members without shared inboxes
- Not validating HTML rendering across email clients before launch
Install this skill directly: skilldb add email-services-skills
Related Skills
AWS Ses
Send email at scale with Amazon SES (Simple Email Service). Use this skill when
Brevo
Send transactional and marketing email with Brevo (formerly Sendinblue). Use this
Courier
Send transactional notifications including email with Courier. Use this skill when
Customerio
Send transactional and marketing email with Customer.io. Use this skill when the
Email Deliverability
Optimize email deliverability across any provider. Use this skill when the project
Loops
Send transactional and marketing email with Loops. Use this skill when the project