Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcreigno/nodejs-mail-notifier
nodejs library to listen incoming mail
https://github.com/jcreigno/nodejs-mail-notifier
imap mail nodejs notifier
Last synced: 1 day ago
JSON representation
nodejs library to listen incoming mail
- Host: GitHub
- URL: https://github.com/jcreigno/nodejs-mail-notifier
- Owner: jcreigno
- License: mit
- Created: 2012-05-09T22:10:56.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2022-08-14T12:48:48.000Z (over 2 years ago)
- Last Synced: 2024-10-12T10:10:03.913Z (about 1 month ago)
- Topics: imap, mail, nodejs, notifier
- Language: JavaScript
- Size: 43 KB
- Stars: 168
- Watchers: 5
- Forks: 77
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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 :```javascript
const notifier = require('mail-notifier');const 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', mail => console.log(mail))
.start();
```Keep it running forever :
```javascript
const n = notifier(imap);
n.on('end', () => n.start()) // session closed
.on('mail', mail => console.log(mail.from[0].address, mail.subject))
.start();
```
**Note:** If using a Gmail account, you will need to do two things:
1. Enable IMAP in your Gmail account settings, which is detailed [here](https://support.google.com/mail/answer/7126229?hl=en).
2. Authorize "less secure apps", which you is laid out in "Option 2" [here](https://support.google.com/accounts/answer/6010255?hl=en).installation
------------$ npm install mail-notifier
API
===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']
* `connTimeout` : Number of milliseconds to wait for a connection to be established. Default: 10000
* `authTimeout` : Number of milliseconds to wait to be authenticated after a connection has been established. Default: 5000
* `debug`: *function* - if set, the function will be called with one argument, a string containing some debug info. Default: debug output if [enabled](#debugging).Options from [node-imap](https://github.com/mscdex/node-imap#connection-instance-methods) are also avaliable.
For backward compatibility `username` is supported.
`custommDbg`: *function* - if set, the function will be called with args that contain some mail-notifier debug info. Default: debug output if [enabled](#debugging).
example:
```javascript
const n = notifier(config, (...args) => {
const msg = util.format(...args);
customLogFn(msg);
});
```.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](https://github.com/mscdex/node-imap). For more advanced usage, please consider
using it directly.Debugging
=========Debugging is enabled via the [visionmedia/debug](https://github.com/visionmedia/debug) module.
To enable debug info add `mailnotifier` to the DEBUG env variable :
```sg
$>DEBUG=mailnotifier node sample/simple-mail-notifier.js
```Or to also have imap module debug info :
```sg
$>DEBUG=mailnotifier,imap node sample/simple-mail-notifier.js
```