nodejs library to listen incoming mail
Latest commit c62e805 Jun 26, 2017 @jcreigno committed on GitHub Merge pull request #33 from nickpeleh/master
bump up version to 0.4.0
Failed to load latest commit information.
sample merge upgrade node imap branch Mar 26, 2014
.gitignore merge upgrade node imap branch Mar 26, 2014
LICENSE Create LICENSE Jun 25, 2017 Update Jun 22, 2017
index.js fix wrong dbg message Jun 22, 2017
package.json 0.4.0 Jun 25, 2017


Notify your nodejs scripts of incoming imap mail.


Send mail event for each new email in IMAP INBOX.


Start listening new mails :

const notifier = require('mail-notifier');

const imap = {
  user: "yourimapuser",
  password: "yourimappassword",
  host: "",
  port: 993, // imap port
  tls: true,// use secure connection
  tlsOptions: { rejectUnauthorized: false }

  .on('mail', mail => console.log(mail))

Keep it running forever :

const n = notifier(imap);
n.on('end', () => n.start()) // session closed
  .on('mail', mail => console.log(mail.from[0].address, mail.subject))


$ npm install mail-notifier


notifier(config, customDbg)

The constructor function creates a new notifier. Parameter provide options needed for imap connection. config :

  • host : imap server host
  • port : imap server port number
  • user : imap user name
  • password : imap password
  • tls : need a tle connection to server
  • tlsOptions : see tls module options
  • markSeen: mark mail as read defaults to true
  • box : mail box read from defaults to 'INBOX'
  • search: search query defaults to ['UNSEEN']
  • debug: function - if set, the function will be called with one argument, a string containing some debug info. Default: debug output if enabled.

For backward compatibility username is also supported.

custommDbg: function - if set, the function will be called with args that contain some mail-notifier debug info. Default: debug output if enabled.


const n = notifier(config, (...args) => {
  const msg = util.format(...args);


Start listening for incomming emails.


Stop listening and close IMAP connection.



Sent when a connection to the server has been made.


Sent on incoming new unread email. The parsed Mail is given as first parameter to the event listener.


Sent when an error occurs with the IMAP connection. The first parameter is the err object.


Sent when the IMAP connection is closed. This usually happens after a stop method call.


This module relies heavily on node-imap. For more advanced usage, please consider using it directly.


Debugging is enabled via the visionmedia/debug module.

To enable debug info add mailnotifier to the DEBUG env variable :

$>DEBUG=mailnotifier node sample/simple-mail-notifier.js

Or to also have imap module debug info :

$>DEBUG=mailnotifier,imap node sample/simple-mail-notifier.js