2mail — SMTP relay from Belgian infrastructure

SMTP for Node.js — application mail that arrives

Node.js has no built-in mail function; almost every application uses Nodemailer for that. The library makes sending easy, but says nothing about deliverability: that depends entirely on the SMTP server you send through.

Nodemailer works with a transport. You create an SMTP transport with your relay's details — host, port, encryption and login — and the rest of your code stays untouched. What leaves through a local server or a test account today goes through 2mail tomorrow.

Why it goes wrong without a relay

A Node.js application typically sends mail at the moment it matters: a verification code, a password reset, a booking confirmation. Those are messages expected within seconds. If they leave from a server without reputation, some of them arrive late or not at all — and the user clicks "resend" until they give up.

Setting up SMTP in Node.js

1

Collect your details

Log in to your 2mail account and retrieve your SMTP server, username and password there.

2

Fill them in inside Node.js

Create an SMTP transport in Nodemailer. Set the host to 2mail's SMTP server and the port to 587, and switch the secure option off so the connection is upgraded via STARTTLS. Under auth, fill in the username and password of your 2mail login. Read those details from environment variables, not from the code. Nodemailer has a verify method to check the connection before you send the first real mail — use it.

3

Authenticate your domain

Make sure SPF, DKIM and DMARC are set correctly for your domain, so recipients can verify that the mail comes from you.

4

Test

Send a test message to an address at a major provider and check that it arrives in the inbox and not in the spam folder.

The fields Node.js asks for

Every platform names them slightly differently, but it is always the same five. The actual values are tied to your account and can be found in your 2mail account — take them from there, so you are sure to use the right ones.

Field What you enter
SMTP server (host)The server name from your 2mail account.
PortThe port that matches your chosen encryption; your account shows which one.
EncryptionTLS. Never send unencrypted — your credentials would otherwise travel in plain text.
UsernameThe SMTP login of your 2mail account.
PasswordThe matching password. Never use the password of an employee's mailbox.

Which emails Node.js sends

As soon as the relay is set up, all of these run through 2mail — you do not have to configure them one by one.

Verification codes and email confirmations at sign-up
Password resets and login notifications
Confirmations of bookings, orders or payments
Notifications from background jobs and queues
Error reports and monitoring alerts to administrators

Pitfalls with Node.js

secure and port have to match

The secure option does not mean "safe or unsafe" but "TLS from the first byte". On port 587 secure should be off — STARTTLS follows afterwards. Switch it on anyway and the connection hangs or is dropped immediately, without a clear error.

One transport, reused

Create the transport once at start-up and reuse it, rather than setting up a new one per mail. During a spike — a reminder run, a campaign — you otherwise open hundreds of connections at once, which a relay may read as abuse. Nodemailer can pool connections; enable that for larger volumes.

Wait for the result and log it

Sending is asynchronous. If you do not wait for the server's response or do not log it, you never see that a message was refused. Log at least the message id and any rejection, and preferably hook up 2mail's webhooks for delivery and bounce, so you also see what goes wrong after handover.

SPF, DKIM & DMARC explained About deliverability

A different platform?

SMTP is a standard protocol: any system that speaks SMTP — a CRM, an ERP, a custom application or a server — can send through 2mail using the same five fields.

Frequently asked questions about SMTP for Node.js

Nodemailer sends, but does not provide deliverability: that depends on the SMTP server you send through. A local server or a fresh cloud machine has no authentication and no reputation, so some of your verification and reset emails land in the spam folder. A relay with SPF, DKIM and DMARC fixes that.
Create an SMTP transport with the relay's host, port 587, secure off (STARTTLS) and, under auth, your username and password. Keep those details in environment variables. Call the verify method to test the connection before you send the first real mail.
Off. 2Mail runs on port 587: the connection starts plainly and is upgraded to TLS via STARTTLS. Switch secure on anyway and your client expects TLS from the first byte, leaving you with a connection error or a connection that hangs.
For existing code with Nodemailer, SMTP is the fastest route: only the transport changes. If you send large volumes or want to process delivery status and bounces in your application, 2mail's email API offers an API key per application and signed webhooks. Both can exist side by side.
Call us
Send an email