npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postmaster

v0.1.0

Published

A tiny SMTP server that stores and exposes your emails in an HTTP API for testing

Downloads

2

Readme

Postmaster

Build Status

Postmaster is a tiny SMTP server that stores all messages in memory and exposes an HTTP API to retrieve them later. This makes it really easy to test the headers and the content of your emails.

Installation

Install Postmaster with npm:

$ npm install -g postmaster

You can then run Postmaster with the postmaster command, which should be in your path:

$ postmaster
Postmaster reporting for duty on localhost:5666 (HTTP - localhost:5667)

Change the bound hostname and port with the -l and -p flags, respectively:

$ postmaster -p 4432 -l 127.0.0.1
Postmaster reporting for duty on 127.0.0.1:4432 (HTTP - 127.0.0.1:4433)

HTTP API

The HTTP API will open up on the next port from the Postmaster port. Sending an HTTP GET request to /emails will return a JSON array of the parsed email and associated headers.

$ curl http://localhost:5667/emails
{"1":{"headers":{"User-Agent":"CodeIgniter","Date":"Sat, 28 Apr 2012 17:49:55 +0100","From":"<[email protected]>","Return-Path":"<[email protected]>","To":"[email protected]","Subject":"=?utf-8?Q?Some_random_email?=","Reply-To":"\"[email protected]\" <[email protected]>","X-Sender":"[email protected]","X-Mailer":"CodeIgniter","X-Priority":"3 (Normal)","Message-ID":"<[email protected]>","Mime-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit"},"body":"Oh yeah","html":false,"subject":"Some random email","from":"[email protected]","to":["[email protected]"]}}

Piped through a JSON prettifier, the output looks like this:

$ curl -s http://localhost:5667/emails | python -mjson.tool
{
    "1": {
        "body": "Oh yeah", 
        "from": "[email protected]", 
        "headers": {
            "Content-Transfer-Encoding": "8bit", 
            "Content-Type": "text/plain; charset=utf-8", 
            "Date": "Sat, 28 Apr 2012 17:49:55 +0100", 
            "From": "<[email protected]>", 
            "Message-ID": "<[email protected]>", 
            "Mime-Version": "1.0", 
            "Reply-To": "\"[email protected]\" <[email protected]>", 
            "Return-Path": "<[email protected]>", 
            "Subject": "=?utf-8?Q?Some_random_email?=", 
            "To": "[email protected]", 
            "User-Agent": "CodeIgniter", 
            "X-Mailer": "CodeIgniter", 
            "X-Priority": "3 (Normal)", 
            "X-Sender": "[email protected]"
        }, 
        "html": false, 
        "subject": "Some random email", 
        "to": [
            "[email protected]"
        ]
    }
}

The email's original headers and body are stored and returned, alongside the parsed subject, whether or not the email is HTML, and the from/to address(es).

PHP Example

Assuming we've got an application sending out an email when the user is registered, and we want to test it, we can boot up Postmaster, run the register method and check the HTTP API very easily:

<?php

class Register_Test extends PHPUnit_Framework_TestCase
{
    function testRegistration()
    {
        // Fork out the Postmaster binary and wait until it's ready
        $postmaster = popen('postmaster', 'r');
        $output = fread($postmaster);

        // Register our user
        $model = new User_model();
        $model->register('[email protected]', 'test_password');

        // Grab our emails
        $curl = curl_init('http://localhost:5667/emails');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

        $json = curl_exec($curl);
        curl_close();

        $emails = (array)json_decode($json);

        // Check that the email is what it's supposed to be!
        $this->assertEqual($emails['1']->from, '[email protected]');
        $this->assertEqual($emails['1']->to, '[email protected]');
        $this->assertEqual($emails['1']->subject, 'MyApp - Welcome to MyApp!');

        // Kill the process
        pclose($postmaster);
    }
}

Development / Tests

Grab the most recent copy of the codebase from GitHub:

$ git clone git://github.com/jamierumbelow/postmaster.git postmaster

Install yer modules:

$ npm install

And run the test suite with cake!

$ cake test

If you're developing locally and would like an easy way to rebuild the source, run cake build:

$ cake build && ./bin/postmaster