Exchange Connection Problems

Fix Nodemailer ENETUNREACH Errors with Office 365 SMTP

Tauseeq MagsiTauseeq Magsi Oct 10, 2026 869 views

Question details

The user needs to resolve intermittent connection failures when sending automated emails via Nodemailer using the Office 365 SMTP server.

How to Fix Nodemailer ENETUNREACH Errors with Office 365 SMTP
Product
Microsoft Office 365 SMTP / Node.js
Device & OS
not provided
Scenario
Sending emails through Node.js Nodemailer via smtp.office365.com on port 587.
Observed behavior
Approximately 15% of outgoing messages fail with an ENETUNREACH error, typically when attempting to connect to an IPv6 address, while the remaining messages send successfully.
Before you start

Ensure your Node.js hosting environment has a stable internet connection and verify that your network firewall allows outbound TCP traffic on port 587.

Solution 1Recommended

Force IPv4 Resolution in Nodemailer Configuration

Because the ENETUNREACH error frequently occurs due to unstable IPv6 routing to Microsoft's load balancers, forcing Node.js to connect via IPv4 can immediately stabilize the connection.

Microsoft 365 resolves to multiple IP addresses (both IPv4 and IPv6). If your server lacks proper IPv6 routing, intermittent failures will occur whenever DNS resolves to an IPv6 address.

1
Open your Nodemailer configuration

Locate the file in your Node.js project where the Nodemailer transporter is defined.

2
Modify the transporter options

In the configuration object where you set host to 'smtp.office365.com' and port to 587, add a new property: 'family: 4'. This tells the underlying socket to only use IPv4.

3
Restart the application

Save the changes and restart your Node.js application process. Monitor your application logs to confirm that the intermittent ENETUNREACH errors have stopped.

Force IPv4 Resolution in Nodemailer Configuration
Configuration Check: Ensure your options include 'secure: false' and 'requireTLS: true' as required by Office 365 for port 587.
Free Microsoft Office alternative

Looking for a Lightweight Office Suite Alternative?

If you are encountering complex network restrictions or configuration problems with Microsoft Office 365 services, consider switching to WPS Office for your local document needs. It provides a lightweight, highly compatible alternative that seamlessly handles your daily productivity tasks without requiring complex cloud setups.

  1. 1. Download the software: Visit the official WPS Office website and download the free installer for your operating system.
  2. 2. Install WPS Office: Run the setup file and follow the simple on-screen instructions to complete the installation.
  3. 3. Open existing documents: Launch WPS Office and open your existing Microsoft Office files directly with perfect formatting retention.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Lightweight software that requires significantly fewer system resources to run smoothly.Free to download and use with a highly familiar user interface, requiring zero learning curve.Excellent offline capabilities ensuring your work isn't interrupted by network or SMTP server errors.
microsoft office alternative - wps office

Frequently Asked Questions

What does the ENETUNREACH error mean in Node.js?

ENETUNREACH stands for 'Error Network Unreachable'. It means your application attempted to connect to the SMTP server, but the operating system could not find a valid network route to reach that specific IP address. In Office 365, this usually happens when trying to connect via an unconfigured IPv6 route.

Why do my Office 365 SMTP emails succeed most of the time but fail randomly?

Microsoft's Office 365 SMTP server uses DNS round-robin load balancers that resolve to multiple IP addresses, containing a mix of IPv4 and IPv6. If your server's IPv6 routing is unstable, only the connections assigned to the faulty IPv6 path will fail, resulting in an intermittent success rate.

Can I use port 465 instead of 587 for Office 365 SMTP in Nodemailer?

No. Microsoft 365 officially requires port 587 with STARTTLS for SMTP client submission. Port 465 (Implicit SSL) is generally not supported for standard Office 365 SMTP connections and will result in connection timeouts or authentication failures.