• Stars
    star
    132
  • Rank 266,470 (Top 6 %)
  • Language
    CoffeeScript
  • Created about 12 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Overview

Mail listener library for node.js. Get notification when new email arrived to inbox. Uses IMAP protocol.

We are using these libraries: node-imap, mailparser.

Heavily inspired by this gist.

Use

Install

npm install mail-listener

JavaScript Code:

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

var mailListener = new MailListener({
  username: "imap-username",
  password: "imap-password",
  host: "imap-host",
  port: 993, // imap port
  secure: true, // use secure connection
  mailbox: "INBOX", // mailbox to monitor
  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`
});

mailListener.start();

mailListener.on("server:connected", function(){
  console.log("imapConnected");
});
  
mailListener.on("mail:arrived", function(id){
  console.log("new mail arrived with id:" + id);
});

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

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

CoffeeScript Code:

MailListener = require "mail-listener"

mailListener = new MailListener
  username: "imap-username"
  password: "imap-password"
  host: "imap-host"
  port: 993 # imap port
  secure: true # use secure connection
  mailbox: "INBOX" # mailbox to monitor
  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`


 # start listener. You can stop it calling `stop method`
mailListener.start()

# subscribe to server connected event
mailListener.on "server:connected", ->
  console.log "imap connected"

# subscribe to error events
mailListener.on "error", (err) ->
  console.log "error happened", err

# mail arrived and was parsed by parser 
mailListener.on "mail:parsed", (mail) ->
  # do something with mail object including attachments
  console.log "parsed email with attachment", mail.attachments
  ## mail processing code goes here

## it's possible to access imap object from node-imap library for performing additional actions. E.x.
mailListener.imap.move :msguids, :mailboxes, ->

That's easy!

Contributions

Mail-listener is ready to use in your project. However if you need any feature tell us or fork project and implement it by yourself.

We appreciate feedback!

License

(The MIT License)

Copyright (c) 2011-2013 CircuitHub., https://circuithub.com/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

rel8

Hey! Hey! Can u rel8?
Haskell
146
star
2

elm-bootstrap-html

Html shorthand for Bootstrap
Elm
54
star
3

elm-semantic-ui

A reasonably type-safe interface to creating Semantic UI based applications
Elm
42
star
4

elm-html-shorthand

Html shorthand for Elm
Elm
32
star
5

fast-downward

Solve classical planning problems (STRIPS/SAS+) using Haskell & Fast Downward
Haskell
32
star
6

massive-git

Implementation of the Git objet model on Riak, distributed revision control at scale.
CoffeeScript
29
star
7

haskell-gerber

A library for parsing Gerbers
Haskell
18
star
8

morpheus

Browser side Constructive Solid Geometry.
JavaScript
13
star
9

nix-buildkite

Take a Nix job description and turn it into separate Buildkite steps with dependencies
Haskell
11
star
10

oso

Haskell bindings to the Polar query engine and Oso authorization library
Haskell
11
star
11

elm-angular-experiments

Interop experiments between elm and angular
Elm
8
star
12

ch-hs-format

CircuitHub's Haskell source code formatter
Haskell
7
star
13

atmosphere

Reliable Firebase-backed Jobs Queue (Deprecated - please don't use)
JavaScript
6
star
14

ch-hs-imports

Haskell
6
star
15

nix-buildkite-buildkite-plugin

A Buildkite plugin to generate a pipeline from a Nix expression
Haskell
5
star
16

circuithub-prelude

CircuitHub's Prelude. Builds on top of the ClassyPrelude.
Haskell
4
star
17

riak-entity

Tiny library on top of riak-js to work with Riak in OO style.
CoffeeScript
4
star
18

persistent-mysql-extra

MySQL-specific queries for use with persistent
Haskell
4
star
19

doc-viewer

HTML5 pdf viewer control based on pdf.js
JavaScript
4
star
20

haskell-filepicker-policy

Utility functions for generating signed filepicker.io policies for URLs
Haskell
3
star
21

persistent-chunked

Helpers for running chunked queries with persistent
Haskell
3
star
22

haskell-access

A type-safe access control scheme
Haskell
3
star
23

comparable-key

Eq, Ord and Hashable classes and instances for the key part of a data type
Haskell
2
star
24

node-files

Simple files' utilities for Node.js
CoffeeScript
2
star
25

git-commit-info

Simple utility that allows to get the latest commit info from git repository
CoffeeScript
2
star
26

node-objects

Simple objects' utilities for Node.js
CoffeeScript
2
star
27

elm-array-focus

Focus helpers for Array
Elm
1
star
28

elm-graphics-shorthand

Shorthand for working with Graphics
Elm
1
star
29

elm-bootstrap

A collection of packages for working with Bootstrap in Html
1
star
30

cachix-buildkite-plugin

A Buildkite plugin to enable Cachix
1
star
31

elm-flex-html

Flex layout for Html similar to Elm's builtin flow layout
1
star
32

d3-serverside

D3 fork for server-side use
JavaScript
1
star
33

elm-filepickerio-api-types

Unofficial, basic types for the Filepicker.io API
Elm
1
star
34

elm-list-signal

List functions lifted into Signal
Elm
1
star