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 sendmailVerified import paths — ran on the pinned version, not inferred.
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.
Replace `content` with `html` for the email body in mail options. Refer to `mailcomposer` documentation for full options.
Upgrade your Node.js runtime to version 6.0.0 or higher to be compatible with ES2015 syntax.
Evaluate actively maintained alternatives like `Nodemailer` for production environments. If used, pin the version and monitor for critical issues independently.
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.
Change `const sendmail = require('sendmail');` to `const sendmail = require('sendmail')();` or `const sendmail = require('sendmail')({});` if passing options.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.
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.