Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smtp-server

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smtp-server

Create custom SMTP servers on the fly

  • 3.4.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
142K
decreased by-1.58%
Maintainers
1
Weekly downloads
 
Created

What is smtp-server?

The smtp-server npm package is a simple and powerful SMTP server library for Node.js. It allows you to create custom SMTP servers for receiving and processing emails. This package is useful for testing email sending functionality, building email processing systems, and more.

What are smtp-server's main functionalities?

Basic SMTP Server

This code sets up a basic SMTP server that listens on port 25. It prints incoming email messages to the console.

const SMTPServer = require('smtp-server').SMTPServer;

const server = new SMTPServer({
  onData(stream, session, callback) {
    stream.pipe(process.stdout); // Print message to console
    stream.on('end', callback);
  }
});

server.listen(25, () => {
  console.log('SMTP server is listening on port 25');
});

Authentication

This code sets up an SMTP server with basic authentication. It checks the username and password provided by the client.

const SMTPServer = require('smtp-server').SMTPServer;

const server = new SMTPServer({
  onAuth(auth, session, callback) {
    if (auth.username === 'user' && auth.password === 'pass') {
      callback(null, { user: 'user' });
    } else {
      callback(new Error('Invalid username or password'));
    }
  }
});

server.listen(25, () => {
  console.log('SMTP server with authentication is listening on port 25');
});

Custom Message Handling

This code sets up an SMTP server that parses incoming email messages and logs the subject and text content to the console.

const SMTPServer = require('smtp-server').SMTPServer;
const simpleParser = require('mailparser').simpleParser;

const server = new SMTPServer({
  onData(stream, session, callback) {
    simpleParser(stream, (err, parsed) => {
      if (err) {
        callback(err);
      } else {
        console.log('Subject:', parsed.subject);
        console.log('Text:', parsed.text);
        callback();
      }
    });
  }
});

server.listen(25, () => {
  console.log('SMTP server with custom message handling is listening on port 25');
});

Other packages similar to smtp-server

Keywords

FAQs

Package last updated on 16 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc