Minimal Node.js example (built-in http module, no web framework) that sends test mail through Mailexam SMTP via Nodemailer.
Based on the Mailexam Node.js guide.
- A Mailexam account and a project with SMTP credentials.
- Node.js 18+ and npm.
From your Mailexam welcome email or dashboard:
| Variable | Description |
|---|---|
MAILEXAM_LOGIN |
SMTP login (for example, xxxxx) |
MAILEXAM_PASSWORD |
SMTP password (paired with the login) |
| Host | {MAILEXAM_LOGIN}.mailexam.ru (built automatically in code) |
- Install dependencies:
npm install- Copy the example environment file and fill in your credentials:
cp .env.example .env- Edit
.env:
MAILEXAM_LOGIN=YOUR_LOGIN
MAILEXAM_PASSWORD=YOUR_PASSWORD
MAILEXAM_PORT=587
MAIL_FROM=noreply@example.test- Run the server:
npm startThe server listens on http://127.0.0.1:3000 by default.
- Send a test message:
curl -X POST http://127.0.0.1:3000/mail/test \
-H 'Content-Type: application/json' \
-d '{"to":"user@example.test","subject":"Test","text":"Hello"}'The message appears in the Mailexam dashboard → your project → inbox.
npm run send| Variable | Required | Default | Description |
|---|---|---|---|
MAILEXAM_LOGIN |
yes | — | SMTP login; also used to build the host name |
MAILEXAM_PASSWORD |
yes | — | SMTP password |
MAILEXAM_PORT |
no | 587 |
SMTP port (587, 2525, or 465) |
MAIL_FROM |
no | noreply@example.test |
Sender address (any test address is fine) |
HTTP_HOST |
no | 127.0.0.1 |
HTTP bind address |
HTTP_PORT |
no | 3000 |
HTTP listen port |
For port 587 the transport uses STARTTLS (secure: false). For port 465 it uses SMTPS (secure: true).
.
├── package.json
├── mail.js # Nodemailer transport and sendTest()
├── server.js # HTTP server and POST /mail/test
├── send-test.js # CLI script to send a test message
├── .env.example
├── Dockerfile # for local debugging only
└── docker-compose.yml
Docker is provided for local debugging. For day-to-day development, run the app on the host with npm start (see above).
cp .env.example .env
# edit .env with your credentials
docker compose up --buildThen call the same endpoint on the mapped port:
curl -X POST http://127.0.0.1:3000/mail/test \
-H 'Content-Type: application/json' \
-d '{"to":"user@example.test","subject":"Test","text":"Hello"}'Inside the container the server binds to 0.0.0.0:3000 so the port mapping works.
Set these secrets in your CI environment:
variables:
MAILEXAM_LOGIN: $MAILEXAM_LOGIN
MAILEXAM_PASSWORD: $MAILEXAM_PASSWORD
MAILEXAM_PORT: "587"
MAIL_FROM: "noreply@example.test"After sending a message in a test, verify delivery via the Mailexam API.
Connection timeout / authentication failed
- Host must be
{login}.mailexam.ru, where{login}matchesMAILEXAM_LOGIN. - Login and password must come from the same Mailexam project.
Port 587 and TLS
- For 587:
secure: false(STARTTLS). For 465:secure: true.
Variables not read
- Call
require('dotenv').config()beforerequire('./mail')or export variables in the shell.
Message not in the dashboard
- Open the inbox of the same Mailexam project.
- SMTP errors are printed to
console.erroron a500response.
Port already in use
- Change
HTTP_PORTin.env.
- Mailexam Node.js guide (wiki)
- Express, Fastify, Hapi, NestJS — Node.js with frameworks
- Nodemailer documentation