SMTP trap
The trap is an SMTP server with a login. Give it to a test or staging environment as its outgoing mail server: every message it sends, to any recipient at any domain, is kept in your project and never delivered to the real recipient. You read the messages through the same API and console as mail sent to the project's domain.
Settings
| Setting | Value |
|---|---|
| Host | smtp.eoinbox.com |
| Port | 587 or 2525 |
| Encryption | STARTTLS (required) |
| Username | the project id |
| Password | created in the console: project Settings, SMTP trap, Create password |
The password is shown once. Making a new one stops the old one at once. Messages caught by the
trap carry "source": "trap", and each recipient of a message gets its own copy, so
waitForMessage({ to }) works for any address your application writes to.
The examples below read the values from the environment:
WAITFORMAIL_SMTP_USER=... # the project id
WAITFORMAIL_SMTP_PASSWORD=... # the trap passwordLaravel
In .env of the staging environment:
MAIL_MAILER=smtp
MAIL_HOST=smtp.eoinbox.com
MAIL_PORT=587
MAIL_USERNAME="${WAITFORMAIL_SMTP_USER}"
MAIL_PASSWORD="${WAITFORMAIL_SMTP_PASSWORD}"Laravel's SMTP transport upgrades to TLS with STARTTLS when the server offers it, which the trap always does.
Ruby on Rails
In config/environments/staging.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.eoinbox.com',
port: 587,
user_name: ENV.fetch('WAITFORMAIL_SMTP_USER'),
password: ENV.fetch('WAITFORMAIL_SMTP_PASSWORD'),
authentication: :plain,
enable_starttls: true
}Django
In the staging settings:
import os
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.eoinbox.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True # STARTTLS
EMAIL_HOST_USER = os.environ["WAITFORMAIL_SMTP_USER"]
EMAIL_HOST_PASSWORD = os.environ["WAITFORMAIL_SMTP_PASSWORD"]Node.js with Nodemailer
import nodemailer from 'nodemailer';
export const transport = nodemailer.createTransport({
host: 'smtp.eoinbox.com',
port: 587,
secure: false,
requireTLS: true, // STARTTLS, refuse to send in the clear
auth: {
user: process.env.WAITFORMAIL_SMTP_USER,
pass: process.env.WAITFORMAIL_SMTP_PASSWORD,
},
});
await transport.sendMail({
from: 'shop@example.com',
to: 'customer@example.org',
subject: 'Your order',
text: 'Thanks!',
});The message is kept for customer@example.org in your project; nobody at example.org receives
anything.
When to use which
- The project's domain tests the whole path, your mail provider included: use it for end-to-end tests of production-like environments.
- The trap catches everything an environment sends, to any address, so staging never mails a real customer by mistake.