Skip to content

Documentation

Send email with Nodemailer.

Point a Nodemailer transport at the Mailtruss relay.

Before you start

You need a verified sending domain (see Domains) and an API key (under API keys in the dashboard; it is shown once). For SMTP the key is the password, and a sending-only key is enough. Keep the key in an environment variable on your server, never in code that runs in a browser or an app.

The transport

Create a transport with the relay's host and port, and require TLS. The API key is the password, and any username works.

send.mjs
import nodemailer from "nodemailer";
​
const transport = nodemailer.createTransport({
host: "smtp.mailtruss.com", port: 587, requireTLS: true,
auth: { user: "mailtruss", pass: process.env.MAILTRUSS_API_KEY },
});
await transport.sendMail({ from: "hello@yourdomain.com", to: "delivered@mailtruss.test", subject: "Hi", text: "Sent over SMTP." });

When to use the API instead

If you are writing new Node.js code, the client library is simpler: it returns the message ID, and supports scheduling, templates and batches. Nodemailer over SMTP is for code you already have.

Try it without sending real mail

Send to delivered@mailtruss.test first. It works before any domain is verified and reaches no real mailbox, so you can check your code and see the recorded timeline. Then try bounced@mailtruss.test to see what a bounce looks like. All the test addresses are listed under Sending.

See what happened

Open the message under Emails in the dashboard: it shows the recorded timeline, what each event proves, and a diagnosis if something went wrong. Mail sent over SMTP appears there like any other message. To be told as it happens, add a webhook.

If it fails

The relay answers with a reply code:

  • 535: the API key is wrong or revoked. Fix the password.
  • 550: refused for good (unverified domain, suppressed recipient, invalid message). Do not retry; the reply says why.
  • 552: too large, or the monthly limit is reached.
  • 451 or 452: temporary (rate limit, daily limit, or a brief problem on our side). Retry later; mail servers do this automatically.

Problems that happen after a message is accepted (bounces, complaints) are explained under delivery errors.

Other guides

Last updated

Something wrong or unclear on this page?

Report an issue