# mail-listener2

> Mail listener library for node.js. Get notification when new email arrived.

Latest version **0.3.1** (published 2016-12-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install mail-listener2
pnpm add mail-listener2
yarn add mail-listener2
bun add mail-listener2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2016-12-30 |
| First published | 2013-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 249 |
| Author | Chirag Jain |
| Maintainers | chirag04 |
| Keywords | mail, job, imap, mail listener, email, email parser |

## Links

- npm: https://www.npmjs.com/package/mail-listener2
- Repository: https://github.com/chirag04/mail-listener2
- Issues: https://github.com/chirag04/mail-listener2/issues
- npm.io page: https://npm.io/package/mail-listener2

## Dependencies (3)

- [imap](https://npm.io/package/imap.md) ~0.8.14
- [async](https://npm.io/package/async.md) ^0.9.0
- [mailparser](https://npm.io/package/mailparser.md) ~0.4.6

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2016-12-30
- 0.3.0 — 2016-12-29
- 0.2.0 — 2016-08-25
- 0.1.8 — 2015-03-09
- 0.1.7 — 2014-07-30
- 0.1.6 — 2014-07-23
- 0.1.5 — 2014-07-17
- 0.1.4 — 2014-07-08
- 0.1.3 — 2014-05-02
- 0.1.2 — 2014-05-02
- 0.1.1 — 2014-02-26
- 0.1.0 — 2013-10-04

## README

# Overview

Mail-listener2 library for node.js. Get notification when new email arrived to inbox or when message metadata (e.g. flags) changes externally. Uses IMAP protocol.

We are using these libraries: [node-imap](https://github.com/mscdex/node-imap), [mailparser](https://github.com/andris9/mailparser).

Heavily inspired by [mail-listener](https://github.com/circuithub/mail-listener).

## Use

Install

`npm install mail-listener2`


JavaScript Code:


```javascript

var MailListener = require("mail-listener2");

var mailListener = new MailListener({
  username: "imap-username",
  password: "imap-password",
  host: "imap-host",
  port: 993, // imap port
  tls: true,
  connTimeout: 10000, // Default by node-imap
  authTimeout: 5000, // Default by node-imap,
  debug: console.log, // Or your custom function with only one incoming argument. Default: null
  tlsOptions: { rejectUnauthorized: false },
  mailbox: "INBOX", // mailbox to monitor
  searchFilter: ["UNSEEN", "FLAGGED"], // the search filter being used after an IDLE notification has been retrieved
  markSeen: true, // all fetched email willbe marked as seen and not fetched next time
  fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
  mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
  attachments: true, // download attachments as they are encountered to the project directory
  attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
});

mailListener.start(); // start listening

// stop listening
//mailListener.stop();

mailListener.on("server:connected", function(){
  console.log("imapConnected");
});

mailListener.on("server:disconnected", function(){
  console.log("imapDisconnected");
});

mailListener.on("error", function(err){
  console.log(err);
});

mailListener.on("mail", function(mail, seqno, attributes){
  // do something with mail object including attachments
  console.log("emailParsed", mail);
  // mail processing code goes here
});

mailListener.on("attachment", function(attachment){
  console.log(attachment.path);
});

// it's possible to access imap object from node-imap library for performing additional actions. E.x.
mailListener.imap.move(:msguids, :mailboxes, function(){})

```

That's easy!

## Attachments
Attachments can be streamed or buffered. This feature is based on how [mailparser](https://github.com/andris9/mailparser#attachments) handles attachments.
Setting `attachments: true` will download attachments as buffer objects by default to the project directory.
A specific download directory may be specified by setting `attachmentOptions: { directory: "attachments/"}`.
Attachments may also be streamed using `attachmentOptions: { stream: "true"}`. The `"attachment"` event will be fired every time an attachment is encountered.
Refer to the [mailparser docs](https://github.com/andris9/mailparser#attachment-streaming) for specifics on how to stream attachments.


## License

MIT

---
_Source: https://npm.io/package/mail-listener2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
