Skip to main content
Technology & EngineeringEmail Services187 lines

Mailtrap

Send and test email with Mailtrap. Use this skill when the project needs to integrate Mailtrap for email testing in development, transactional email sending in production, email previewing, HTML validation, spam score checking, or sandbox email capture. Covers both Mailtrap Email Testing (sandbox) and Mailtrap Email Sending (production transactional API).

Quick Summary34 lines
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: 187 lines
Paste into your CLAUDE.md or agent config

Mailtrap 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:

FeatureWhat it does
HTML previewRender email across email clients
Spam scoreCheck SpamAssassin score before sending
HTML validationDetect broken tags, missing attributes
Blacklist checkVerify sending domain isn't blacklisted
Screenshot previewSee rendering in popular email clients
Raw messageInspect full MIME headers

Webhook Processing

EventAction
deliveryMark delivered
bounceSuppress address
soft_bounceLog, monitor
complaintSuppress from marketing
openUpdate engagement
clickUpdate 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

Get CLI access →

Related Skills

Nodemailer

Send email with Nodemailer in Node.js. Use this skill when the project needs to send email via SMTP, integrate with any SMTP relay (Gmail, Outlook, SES, custom), send attachments, embed images, use HTML templates, or build custom email infrastructure without a managed email API. Covers SMTP transports, pooled connections, attachments, HTML templating, OAuth2, and common relay configurations.

Email Services224L

Plunk

Send transactional and marketing email with Plunk. Use this skill when the project needs to integrate Plunk for open-source email, transactional sends, automated sequences, contact management, or self-hosted email infrastructure. Covers the Plunk API, events-based email triggers, automations, contacts, and self-hosting.

Email Services160L

Postmark

Send transactional email with Postmark. Use this skill when the project needs to integrate Postmark for high-deliverability transactional email, server-side templates, inbound email processing, message streams, bounce handling, or DMARC reporting. Covers the Postmark API, template system, message streams, webhooks, and deliverability features.

Email Services211L

React Email

Build email templates with React Email. Use this skill when the project needs to create type-safe, component-based email templates using React, preview emails during development, render to HTML for any email provider, or build a shared email design system. Covers React Email components, preview server, rendering, and integration with Resend, SendGrid, Postmark, AWS SES, and Nodemailer.

Email Services233L

Resend

Send transactional and marketing email with Resend. Use this skill when the project needs to integrate Resend for sending email, managing contacts, handling webhooks, building templates, or setting up mailing lists and broadcasts. Covers single sends, batch sends, scheduling, React Email templates, domain verification, webhook processing, idempotency, deliverability, and compliance.

Email Services244L

Sendgrid

Send transactional and marketing email with SendGrid (Twilio). Use this skill when the project needs to integrate SendGrid for sending email via API or SMTP, dynamic templates, contact management, marketing campaigns, email validation, webhook event processing, or deliverability optimization. Covers the v3 Mail Send API, dynamic transactional templates, Marketing Campaigns, suppressions, and Event Webhook.

Email Services220L