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

test-smtp-server

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-smtp-server

The test-smtp-server package allows internal testing of projects needing an SMTP server.

  • 0.9.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
75
increased by19.05%
Maintainers
1
Weekly downloads
 
Created
Source

Test SMTP Server

Test SMTP Server is a lightweight wrapper for smtp-server. It is primarily intended for development and testing. The test code can start the server, run email tests and then validate the email contents. It can replace the use of external fake SMTP services which may have availablility issues.

All received emails are stored in an array in the order received. The emails may be viewed as raw data or a parsed object that is easily examined.

Getting Started

Prerequisites

Tested on Node v18 with npm v9.

Installation

npm install test-smtp-server --save-dev

Usage

See test code for an example.

import { testSmtpServer } from "test-smtp-server";

(async (): Promise<void> => {
  const smtpserver = new testSmtpServer();
  await smtpserver.startServer();   // start listening

  // send some emails capturing ids ..
  messageId.push( await sendMail(email, smtpOptions));

  // get emails in sent order
  const mails = smtpserver.getEmails();

  // validate/dump emails

  if (mails.length) {
    let entry = 0;
    for (const mail of mails) {
      console.log(`Checking mail entry <${entry}>`);
      console.log(mail.envelope);
      const parsed = await mail.getParsed();
      if (parsed.messageId !== messageId[entry]) {
        throw new Error(`Messageids do not match for email ${
          entry} <${parsed.messageId}> <${messageId[entry]}>`);
      }

      console.log(parsed);
      entry++;
    }
  } else {
    throw new Error("No emails captured when expected");
  }

  await smtpserver.stopServer();    // terminate server

Security

The server is started as secure but that may not be possible in the testing environment. If the server does not have a valid certificate, the connection will fail from the client side. Some clients (e.g. nodemailer/SMTP-Transport options) allow connections to non-secure servers. Node allows connections through an environment variable that turns off certificate authorization checking. See node_tls_reject_unauthorizedvalue for more information. This may be insecure if other ports are used.

License

This project is licensed under the MIT License - see the LICENSE file for details

Keywords

FAQs

Package last updated on 31 Jul 2023

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