simplesmtp: Simple SMTP Server and Client Module
simplesmtp is a Node.js module designed for creating custom SMTP servers and clients, primarily targeting older Node.js environments (v0.6 to v0.8+). The package, currently at version 0.3.35, is explicitly deprecated and no longer maintained. It was developed without Node.js v0.10 streams, indicating significant compatibility challenges with Node.js v0.12 and newer versions. While it offers basic SMTP functionality suitable for integration testing, it lacks active development, security updates, and modern features. Users are strongly advised to migrate to modern alternatives like `smtp-server` for server implementations, `smtp-connection` for client-side operations, or `Haraka` for full-featured SMTP applications, which offer better performance, security, and compatibility with current Node.js releases. There is no ongoing release cadence.
Common errors
-
TypeError: req.pipe is not a function
cause This error likely occurs when running `simplesmtp` on Node.js versions v0.12 or newer. The module was written for older Node.js streams and is incompatible with modern stream APIs.fixThis package is fundamentally incompatible with modern Node.js. Replace `simplesmtp` with a contemporary, actively maintained SMTP library like `smtp-server`. -
Error [ERR_REQUIRE_ESM]: require() of ES Module ... is not supported.
cause You are attempting to use the CommonJS `require()` function in an ES Module context, or trying to `import` a CommonJS module in a way that is not directly supported by Node.js, possibly due to `type: module` in `package.json`.fixThis package is strictly CommonJS. If your project is an ESM project, you will need to wrap the `require` call or, preferably, switch to a modern, ESM-compatible SMTP library. For this specific package, ensure your environment is CommonJS compatible (e.g., remove `"type": "module"` from `package.json` if possible, or use a CommonJS entry point). -
Cannot find module 'simplesmtp'
cause The `simplesmtp` package has not been installed, or there is a typo in the `require()` path.fixRun `npm install simplesmtp` to add the package to your project dependencies. Verify the spelling of the module name in your `require()` statement.
Warnings
- breaking This module is officially deprecated and no longer maintained. It does not use Node.js v0.10 streams and is explicitly stated to have a 'rocky future' with Node.js v0.12+. Using it with modern Node.js versions (v0.12+) will likely result in runtime errors related to stream APIs or other breaking changes.
- deprecated Security vulnerabilities in this abandoned package will not be patched. Using `simplesmtp` in production environments or with sensitive data is highly discouraged due to the lack of security updates and potential for undiscovered exploits.
- gotcha Compatibility with Node.js v0.6 requires using `simplesmtp` v0.2.7. Later versions (v0.3.x) are designed for Node.js v0.8+.
- breaking The module is CommonJS-only. Attempting to use ESM `import` statements will result in a runtime error.
Install
-
npm install simplesmtp -
yarn add simplesmtp -
pnpm add simplesmtp
Imports
- simplesmtp
import simplesmtp from 'simplesmtp';
const simplesmtp = require('simplesmtp'); - createSimpleServer
import { createSimpleServer } from 'simplesmtp';const simplesmtp = require('simplesmtp'); simplesmtp.createSimpleServer(/* options */, requestListener); - createServer
const server = require('simplesmtp').createServer();const simplesmtp = require('simplesmtp'); const server = simplesmtp.createServer(/* options */);
Quickstart
const simplesmtp = require('simplesmtp');
const PORT = process.env.SMTP_PORT || 2525;
simplesmtp.createSimpleServer({
SMTPBanner: "My Test SMTP Server",
debug: true
}, function(req) {
console.log(`[simplesmtp] New message from: ${req.from}`);
console.log(`[simplesmtp] To: ${req.to.join(', ')}`);
console.log(`[simplesmtp] Host: ${req.host}`);
console.log(`[simplesmtp] Client IP: ${req.remoteAddress}`);
// Pipe the incoming email data to stdout
console.log('\n--- Email Body Start ---');
req.pipe(process.stdout);
req.on('end', () => {
console.log('\n--- Email Body End ---');
// Accept the message after processing
req.accept();
console.log(`[simplesmtp] Message accepted from ${req.from}`);
});
}).listen(PORT, function() {
console.log(`[simplesmtp] Simple SMTP server listening on port ${PORT}`);
console.log('Send an email to this server (e.g., via telnet: `telnet localhost 2525`, then SMTP commands like `MAIL FROM:<test@example.com>`, `RCPT TO:<recipient@example.com>`, `DATA`, `Subject: Test\n\nHello world!\n.`)');
});