Registry / communication / sendmail

sendmail

JSON →
library2.0jsnpmunverified

The `sendmail` package for Node.js provides a direct method for sending emails without relying on an external SMTP server. Instead, it resolves MX records for recipient domains and attempts to deliver mail directly. The current stable version is 1.6.1, though development appears to have ceased, with the last significant update converting to ES2015 in version 1.2.0. This library uses `mailcomposer` internally to handle email formatting, supporting HTML content, attachments, and DKIM signing. It also features a development mode for local testing without sending actual emails. Its primary differentiator is the direct delivery approach, contrasting with libraries that typically require SMTP relay configuration, making it suitable for specific application architectures or testing scenarios where a full SMTP setup is not desired.

npm install sendmail
INSTALL
IMPORT
SIG · SENDMAIL
S
sendmail
communicationjavascriptv2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sendmail
const sendmail = require('sendmail')();
const sendmail = require('sendmail');
The `require('sendmail')` returns an initializer function which must be called to configure and return the actual mail sending function.
sendmail (with options)
const sendmail = require('sendmail')({ silent: true });
import sendmail from 'sendmail';
Configuration options are passed directly to the initializer function. While 1.2.0 converted to ES2015, the documentation primarily shows CommonJS `require` syntax. For ESM, treat it as a default export that is an initializer function.
sendmail (ESM)
import sendmailFactory from 'sendmail'; const sendmail = sendmailFactory();
import { sendmail } from 'sendmail';
Assuming a default export of the initializer function for ESM environments based on its CommonJS pattern. The factory function must be called to get the mailer instance.

Demonstrates initializing `sendmail` with basic logging and development mode settings, then sending a simple HTML email with error handling. Uses ESM import style for modern Node.js environments.

import sendmailFactory from 'sendmail'; // Configure sendmail. In a real app, use environment variables for sensitive data. // Use devPort and devHost for local testing without sending actual emails. const sendmail = sendmailFactory({ logger: { debug: console.log, info: console.info, warn: console.warn, error: console.error }, silent: false, // Set to true to suppress console output devPort: 1025, // For development mode, e.g., use with MailHog or similar local SMTP server devHost: 'localhost' // Host for development mode }); // Send an email sendmail({ from: 'your-app@yourdomain.com', to: 'recipient@example.com', subject: 'Hello from Node-Sendmail!', html: '<h1>Welcome!</h1><p>This is a test email sent without an SMTP server.</p>', // You can also add attachments: // attachments: [{ // filename: 'text1.txt', // content: 'hello world!' // }] }, function(err, reply) { if (err) { console.error('Email sending failed:', err && err.stack); } else { console.log('Email sent successfully:', reply); } });
Debug
Known issues
breakingThe `content` option for email body was replaced by `html` for versions 1.0.0 and above. Old implementations using `content` will fail.
fix
Replace `content` with `html` for the email body in mail options. Refer to `mailcomposer` documentation for full options.
affects: <1.0.0
breakingVersion 1.2.0 converted the codebase to ES2015, dropping compatibility with Node.js 4.x. Applications running on Node.js 4.x will encounter syntax errors.
fix
Upgrade your Node.js runtime to version 6.0.0 or higher to be compatible with ES2015 syntax.
affects: >=1.2.0
gotchaThe `sendmail` package appears to be abandoned, with no significant commits or releases in several years. Users should be aware of potential unaddressed bugs, security vulnerabilities, or compatibility issues with newer Node.js versions or email standards. It may not be suitable for new, production-critical applications.
fix
Evaluate actively maintained alternatives like `Nodemailer` for production environments. If used, pin the version and monitor for critical issues independently.
affects: >=1.6.1
gotchaDirect mail sending without an SMTP relay can sometimes lead to emails being marked as spam due to sender reputation issues or strict DMARC/SPF/DKIM policies on recipient servers, especially without proper DKIM signing and SPF records.
fix
Ensure your domain has correctly configured SPF and DKIM records. Implement DKIM signing using the `dkim` option in `sendmail` if your private key is available.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: sendmail is not a function
The `sendmail` module exports an initializer function, which must be called to return the actual mail sending function.
fix
Change `const sendmail = require('sendmail');` to `const sendmail = require('sendmail')();` or `const sendmail = require('sendmail')({});` if passing options.
Error: getaddrinfo ENOTFOUND example.com
This error typically indicates that the DNS lookup for the recipient's mail server failed, either due to a non-existent domain, network connectivity issues, or an invalid MX record.
fix
Check the recipient's email address for typos. Verify your network connectivity and DNS resolver settings. Ensure the domain example.com actually exists and has valid MX records.
Error: Can't parse private key for DKIM
The DKIM private key provided in the options is either malformed, not in the correct format (e.g., PEM), or the file path is incorrect.
fix
Ensure the `privateKey` path points to a valid .pem file, and its content is a correctly formatted DKIM private key. The file should be readable by the Node.js process.
Upgrade
Version history
2.0latest on npm
Audit
Dependencies
mailcomposerrequiredUsed internally for email composition and formatting, providing support for HTML, attachments, and various mail options.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
sendmail — npm install sendmail · libregistry