NPM Star
Collections
  1. Home
  2. Compare
  3. nodemailer vs sendgrid
NPM Compare

Compare NPM packages statistics, trends, and features

CollectionsVS Code extensionChrome extensionTermsPrivacyLinkTreeIndiehackersBig Frontendqiuyumi

Nodemailer vs Sendgrid comparison

Compare nodemailer vs sendgrid for email use cases, including package popularity, downloads, ecosystem fit, and practical tradeoffs.

Emailemailnpmcomparisonnodemailersendgrid

Unable to load comparison data. Please try again later.

Nodemailer

Nodemailer

Send emails from Node.js – easy as cake! 🍰✉️

NPM

See nodemailer.com for documentation and terms.

Nodemailer is developed by the team behind EmailEngine, a self-hosted email API that turns any Gmail, Microsoft 365, or IMAP account into a REST endpoint, with managed OAuth2, webhooks for incoming mail, and built-in sending. If you would rather call an HTTP API than maintain IMAP and SMTP connections yourself, that is what it is for.

Supported runtimes

Nodemailer targets Node.js 20 and later. The ES module build also runs on Bun (tested against the latest release) and on Cloudflare Workers with the nodejs_compat compatibility flag. On Workers only the SMTP based transports apply, sendmail needs a child process, and the runtime does not allow turning certificate validation off, so tls.rejectUnauthorized: false fails there with an error.

Cancelling an individual SMTP send

Pass an AbortSignal in the message options to cancel one sendMail() call:

await transporter.sendMail({ from: 'sender@example.com', to: 'recipient@example.com', text: 'Hello', signal: AbortSignal.timeout(30_000) });

This is supported by SMTP and pooled SMTP transports. A pre-aborted signal prevents processing; aborting later stops subsequent plugin processing, removes a queued message, or closes the SMTP connection assigned to that message. Other deliveries in the pool can continue. Both promise and callback forms report an error named AbortError, with code: 'EABORT' and the signal's reason as cause. The signal listener is removed when the send finishes.

Cancellation stops local processing; it does not prove that the SMTP server has not already accepted the message. Do not retry a cancelled send automatically on that assumption.

Work already started by a plugin or a custom getSocket hook requires that code's cooperation to stop. Nodemailer ignores late plugin completion and destroys a socket handed back after cancellation. Plugins can read mail.data.signal to cancel their own work.

Other bundled transports (stream, JSON, sendmail and SES) ignore the signal once the message is handed to them, so the message is sent normally. A signal that is already aborted, or aborts while plugins run, still cancels the send with EABORT on every transport, as that happens before the transport is called. A signal value that is not an AbortSignal fails the send with ECONFIG. Custom transports can opt in with supportsAbortSignal: true; their send() must register its abort listener synchronously, check for a pre-aborted signal, stop the work it owns, invoke its callback once, and remove the listener on completion.

SMTP socket close timeout

When an SMTP connection closes, Nodemailer ends the socket and destroys it if the server has not closed its side within socketCloseTimeout milliseconds (default 5000). Set it to 0 to destroy the socket right away. This applies to SMTP and pooled SMTP, including aborted sends and transporter.close({ force: true }). It does not tell you whether the server accepted a message that was in flight.

Having an issue?

First review the docs

Documentation for Nodemailer can be found at nodemailer.com.

Nodemailer fails to load or throws a SyntaxError

Nodemailer 10 and later require Node.js 20 or newer. The package ships both ES module and CommonJS builds, so import nodemailer from 'nodemailer' and const nodemailer = require('nodemailer') both work. If you need to run on an older Node.js version, stay on the 9.x line.

I'm having issues with Gmail

Gmail either works well, or it does not work at all. It is probably easier to switch to an alternative service instead of fixing issues with Gmail. If Gmail does not work for you, then don't use it. Read more about it here. If the blocker is OAuth2 setup rather than Gmail itself, EmailEngine handles the OAuth2 flow and token refresh for you.

I get ETIMEDOUT errors

Check your firewall settings. Timeout usually occurs when you try to open a connection to a firewalled port either on the server or on your machine. Some ISPs also block email ports to prevent spamming.

Nodemailer works on one machine but not in another

It's either a firewall issue, or your SMTP server blocks authentication attempts from some servers.

I get TLS errors

  • If you are running the code on your machine, check your antivirus settings. Antiviruses often mess around with email ports usage. Node.js might not recognize the MITM cert your antivirus is using.
  • Latest Node versions allow only TLS versions 1.2 and higher. Some servers might still use TLS 1.1 or lower. Check Node.js docs on how to get correct TLS support for your app. You can change this with tls.minVersion option
  • You might have the wrong value for the secure option. This should be set to true only for port 465. For every other port, it should be false. Setting it to false does not mean that Nodemailer would not use TLS. Nodemailer would still try to upgrade the connection to use TLS if the server supports it.
  • Older Node versions do not fully support the certificate chain of the newest Let's Encrypt certificates. Either set tls.rejectUnauthorized to false to skip chain verification or upgrade your Node version
let configOptions = { host: 'smtp.example.com', port: 587, tls: { rejectUnauthorized: true, minVersion: 'TLSv1.2' } };

I have issues with DNS / hosts file

Node.js uses c-ares to resolve domain names, not the DNS library provided by the system, so if you have some custom DNS routing set up, it might be ignored. Nodemailer runs dns.resolve4() and dns.resolve6() to resolve hostname into an IP address. If both calls fail, then Nodemailer will fall back to dns.lookup(). If this does not work for you, you can hard code the IP address into the configuration like shown below. In that case, Nodemailer would not perform any DNS lookups.

let configOptions = { host: '1.2.3.4', port: 465, secure: true, tls: { // must provide server name, otherwise TLS certificate check will fail servername: 'example.com' } };

I have an issue with TypeScript types

Nodemailer 10 and later are written in TypeScript and ship their own type definitions, so @types/nodemailer is no longer needed and should be removed from your project to avoid conflicting declarations. The type names follow the layout of the old definitions, so references such as Mail.Options, SMTPTransport.Options or Transporter<SMTPTransport.SentMessageInfo> keep compiling, and the most used types (SendMailOptions, Transporter, SentMessageInfo, Attachment, Address) are exported from the package root. The modules under nodemailer/lib/ are declared with a default export, so import a class as import SMTPTransport from 'nodemailer/lib/smtp-transport' (with esModuleInterop in a CommonJS project). The import SMTPTransport = require(...) and import * as SMTPTransport from ... forms still resolve the type aliases such as SMTPTransport.Options, but they refer to the module rather than to the class, so the class itself has to be imported with a default import. For older Nodemailer versions, the community maintained type definitions still apply.

I have a different problem

If you are having issues with Nodemailer, then the best way to find help would be Stack Overflow or revisit the docs.

License

Nodemailer is licensed under the MIT No Attribution license


The Nodemailer logo was designed by Sven Kristjansen.

THIS PACKAGE HAS MOVED

Please see the latest official package here, thank you!

BuildStatus npm version Email Notifications Badge

NEW: Subscribe to email notifications for releases and breaking changes.

This library allows you to quickly and easily use the SendGrid Web API v3 via Node.js.

Version 3.X.X+ of this library provides full support for all SendGrid Web API v3 endpoints, including the new v3 /mail/send.

This library represents the beginning of a new path for SendGrid. We want this library to be community driven and SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create issues and pull requests or simply upvote or comment on existing issues or pull requests.

Please browse the rest of this README for further detail.

We appreciate your continued support, thank you!

Table of Contents

  • Installation
  • Quick Start
  • Usage
  • Use Cases
  • Announcements
  • Roadmap
  • How to Contribute
  • Troubleshooting
  • About

<a name="installation"></a>

Installation

Prerequisites

  • Node.js version 4, 6 or 7
  • The SendGrid service, starting at the free level

Setup Environment Variables

Update the development environment with your SENDGRID_API_KEY, for example:

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env echo "sendgrid.env" >> .gitignore source ./sendgrid.env

Install Package

The following recommended installation requires npm. If you are unfamiliar with npm, see the npm docs. Npm comes installed with Node.js since node version 0.8.x therefore you likely already have it.

npm install --save sendgrid

Dependencies

  • Nodejs-HTTP-Client

<a name="quick_start"></a>

Quick Start

Hello Email

The following is the minimum needed code to send an email with the /mail/send Helper (here is a full example):

With Mail Helper Class

var helper = require('sendgrid').mail; var fromEmail = new helper.Email('test@example.com'); var toEmail = new helper.Email('test@example.com'); var subject = 'Sending with SendGrid is Fun'; var content = new helper.Content('text/plain', 'and easy to do anywhere, even with Node.js'); var mail = new helper.Mail(fromEmail, subject, toEmail, content); var sg = require('sendgrid')(process.env.SENDGRID_API_KEY); var request = sg.emptyRequest({ method: 'POST', path: '/v3/mail/send', body: mail.toJSON() }); sg.API(request, function (error, response) { if (error) { console.log('Error response received'); } console.log(response.statusCode); console.log(response.body); console.log(response.headers); });

The Mail constructor creates a personalization object for you. Here is an example of how to add to it.

Without Mail Helper Class

The following is the minimum needed code to send an email without the /mail/send Helper (here is a full example):

var sg = require('sendgrid')(process.env.SENDGRID_API_KEY); var request = sg.emptyRequest({ method: 'POST', path: '/v3/mail/send', body: { personalizations: [ { to: [ { email: 'test@example.com' } ], subject: 'Sending with SendGrid is Fun' } ], from: { email: 'test@example.com' }, content: [ { type: 'text/plain', value: 'and easy to do anywhere, even with Node.js' } ] } }); // With promise sg.API(request) .then(function (response) { console.log(response.statusCode); console.log(response.body); console.log(response.headers); }) .catch(function (error) { // error is an instance of SendGridError // The full response is attached to error.response console.log(error.response.statusCode); }); // With callback sg.API(request, function (error, response) { if (error) { console.log('Error response received'); } console.log(response.statusCode); console.log(response.body); console.log(response.headers); });

General v3 Web API Usage

var sg = require('sendgrid')(process.env.SENDGRID_API_KEY); // GET Collection var request = sg.emptyRequest({ method: 'GET', path: '/v3/api_keys' }); // With promise sg.API(request) .then(function (response) { console.log(response.statusCode); console.log(response.body); console.log(response.headers); }) .catch(function (error) { // error is an instance of SendGridError // The full response is attached to error.response console.log(error.response.statusCode); }); // With callback sg.API(request, function (error, response) { if (error) { console.log('Error response received'); } console.log(response.statusCode); console.log(response.body); console.log(response.headers); });

<a name="usage"></a>

Usage

  • SendGrid Docs
  • Library Usage Docs
  • Example Code
  • How-to: Migration from v2 to v3
  • v3 Web API Mail Send Helper

<a name="use_cases"></a>

Use Cases

Examples of common API use cases, such as how to send an email with a transactional template.

<a name="announcements"></a>

Announcements

Please see our announcement regarding breaking changes. Your support is appreciated!

All updates to this library are documented in our CHANGELOG and releases. You may also subscribe to email release notifications for releases and breaking changes.

<a name="roadmap"></a>

Roadmap

If you are interested in the future direction of this project, please take a look at our open issues and pull requests. We would love to hear your feedback.

<a name="contribute"></a>

How to Contribute

We encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details.

  • Feature Request
  • Bug Reports
  • Improvements to the Codebase

<a name="troubleshooting"></a>

Troubleshooting

Please see our troubleshooting guide for common library issues.

<a name="about"></a>

About

sendgrid-nodejs is guided and supported by the SendGrid Developer Experience Team.

sendgrid-nodejs is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-nodejs are trademarks of SendGrid, Inc.

SendGrid Logo

Dependencies Comparison

nodemailer

Dependencies

Dev Dependencies

c812.0.0
tsx4.23.15
libqp3.0.1
proxy1.0.2
bunyan1.8.15
eslint10.15.0
globals17.14.0
libmime5.6.4
mailauth8.0.6
prettier3.10.1
libbase641.4.1
typescript6.0.3
@types/node20.19.43
smtp-server3.21.4
proxy-test-server1.0.0
typescript-eslint8.72.2
@aws-sdk/client-sesv23.1169.0
eslint-config-prettier10.1.8

Peer Dependencies

sendgrid

Dependencies

debug^2.2.0
bottleneck^1.12.0
mailparser^0.6.1
async.queue^0.5.2
lodash.chunk^4.2.0
sendgrid-rest^2.3.0
async.ensureasync^0.5.2

Dev Dependencies

chai^3.5.0
mocha^2.4.5
sinon^1.17.5
eslint^3.1.0
sinon-chai^2.8.0
typescript^2.0.0
mocha-sinon^1.1.5
system-sleep^1.0.0-g

Peer Dependencies

StarsIssuesVersionUpdatedⓘLast publish dateCreatedⓘPackage creation dateSizeⓘMinified + Gzipped size
N
nodemailer
17,715110.6.0a month ago15 years agoinstall size 66.6 KB
S
sendgrid
3,0511035.2.34 years ago14 years agoinstall size 31.9 KB