Code Monkey home page Code Monkey logo

nodejs-mail-notifier's Introduction

mail-notifier

Notify your nodejs scripts of incoming imap mail.

introduction

Send mail event for each new email in IMAP INBOX.

synopsis

Start listening new mails :

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

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

notifier(imap).on('mail',function(mail){console.log(mail);}).start();

Keep it running forever :

var n = notifier(imap);
n.on('end', function () { // session closed
  n.start();
}).on('mail',function(m){
  console.log(m.from[0].address, m.subject);
}).start();

installation

$ npm install mail-notifier

API

notifier(config)

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']

For backward compatibility username is also supported.

.start()

Start listening for incomming emails.

.stop()

Stop listening and close IMAP connection.

Events

'connected'

Sent when a connection to the server has been made.

'mail'

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

'error'

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

'end'

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

Dependencies

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

Debugging

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

nodejs-mail-notifier's People

Contributors

jcreigno avatar fon60 avatar lorenzleutgeb avatar benkaiser avatar

Watchers

James Cloos avatar Yael Brodsky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.