Skip to content

robincunningham2/tmpmail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temporary Mail

NodeJS api for temporary emails

Install

npm install tmpmail

Usage

  • Create a temporary mail client
const TmpMail = require('tmpmail');
const client = TmpMail.Create();
  • Wait for client to initialize, and get your email address
client.on('ready', email => {
  console.log(email);

  // Or, alternatively:
  console.log(client.id);
});

Example output:

  • Fetch messages
client.fetch().then(messages => {
  console.log(messages);
});

Example output:

[
  {
    _id: '3e1ee21c5cce2436daa1e8206923695e',
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Hello world!',
    date: 2021-02-09T11:46:42.000Z
  },
  {
    _id: '3e1ee21c5cce2436daa1e8206923b38a',
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Hello world (for the second time)!',
    date: 2021-02-09T11:46:57.000Z
  }
]
  • Get email body
client.findMessage('3e1ee21c5cce2436daa1e8206923695e').then(msg => {
  console.log(msg);
});

Example output:

{
  _id: '3e1ee21c5cce2436daa1e8206923695e',
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello world!',
  date: 2021-02-09T11:46:42.000Z,
  body: {
    text: 'Hello world from a stranger!',
    html: ''
  }
}
  • Create a message listener
// Check every 1000ms (1s) for new messages
client.startMessageListener(1000, msgs => {
  console.log('Got some new message(s):\n', msgs);
});

// Stop the listener after 10s
setTimeout(client.stopMessageListener, 10000);

License

Apache 2.0