Skip to main content
Nodemailer is the most popular email library for Node.js. You can connect to mySMTP with STARTTLS on port 587 and verify the connection before sending.

Prerequisites

  • Node.js 18 or later
  • Your mySMTP username and password from the setup email
  • Your mySMTP hostname from the setup email (shown as relayxx.mysmtp.com in these examples)

Install Nodemailer

Basic send example

Replace relayxx.mysmtp.com with your real hostname from the mySMTP setup email. Load credentials from environment variables, never hardcode them in source files.

Verify the connection before sending

HTML email with attachment

Always set requireTLS: true when using port 587. This prevents Nodemailer from falling back to an unencrypted connection if TLS negotiation fails.

Common errors

Your username or password is incorrect, or your account is not yet activated. Re-enter credentials exactly as shown in the setup email. See Setting up SMTP credentials.
Your network or host may block port 587. Try port 2525 with the same settings, or port 465 with secure: true. See Supported SMTP ports and encryption.
The secure and requireTLS settings do not match the port. For port 587, use secure: false and requireTLS: true. For port 465, use secure: true and remove requireTLS.
Test your SPF, DKIM, and DMARC setup with the mySMTP Deliverability Toolbox before sending large volumes.