node package manager
Stop wasting time. Easily manage code sharing in your team. Create a free org »

ethereal-email

Ethereal Email

Create ethereal email addresses on the fly from your application.

EtherealEmail acquires a new email address from ethereal.email and starts listening for messages sent to this address.

This is useful for testing email applications where you want to use vanity addresses but also to be able to test how the final message looks like. There is an actual roundtrip over the internet so the message received by @ethereal.email addresses should look exactly like messages received by everybody else.

Usage

Retrieve parsed email

The mail object received is a simpleParser object documented in the MailParser docs.

'use strict';
const EtherealEmail = require('ethereal-email');
 
let inbox = new EtherealEmail();
 
inbox.on('email', email => {
    console.log('Listening for messages sent to <%s>', email);
});
 
inbox.connect(mail => {
    console.log('NEW MAIL!');
    console.log(mail);
});

Retrieve raw email stream

If you want to parse the incoming message yourself, then set raw to true

'use strict';
const EtherealEmail = require('ethereal-email');
 
let inbox = new EtherealEmail({
    raw: true
});
 
inbox.on('email', email => {
    console.log('Listening for messages sent to <%s>', email);
});
 
inbox.connect(mail => {
    console.log('NEW MAIL!');
    mail.pipe(process.stdout);
});

How does it work?

There is a MX server running on ethereal.email that proxies all messages to the connected clients, using randomly generated addresses. When your client connects to this server, then a random address is generated and all messages sent to this address are proxied to your client. If the connection between your client and the server breaks, then the address is lost forever.

License

EUPL-1.1