1.0.16 • Published 6 years ago

imap-riyo v1.0.16

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

Install

$ npm install imap-riyo

Introduction

This library is providing a easiest functionality for parsing emails with simple ineterface using imap module. If the authentication will success, you will get a results on 'success' API call based on your configuration.

Please go through the below example:

  var imap = require('imap-riyo');
  var config = {
      username: 'test@gmail.com',
      password: '********',
      host: 'imap.gmail.com',
      debug: 'off',
      mailbox: 'INBOX', 
      searchFilter: ['UNSEEN'],
      mailParserOptions: {streamAttachments: true},
      attachments: true,
      attachmentOptions: { directory: 'attachments',stream:true },
      reCheckMode : false,
      dividerBeforeSignature: '<==================>'
  };

  new imap(config).on('success',function(result){
    console.log(result)
  });

On 'success' API call, you will get a result something like this

{
    "data": [
        {
            "subject": "Hello World",
            "text": " This is a test messages",
            "date": "2018-07-24T06:31:45.000Z",
            "from": [
                {
                    "address": "test4@gmail.com",
                    "name": "Test developer"
                }
            ],
            "to": [
                {
                    "address": "test14@gmail.com",
                    "name": ""
                }
            ],
            "attachment": [
                "Screenshot from 2018-06-06 17-28-05.png",
                "Screenshot from 2018-06-25 18-06-30.png",
                "Screenshot from 2018-06-25 18-33-16.png"
            ]
        }
    ],
    "status": true
}

Others configuration

  var config = {
    username: 'test@gmail.com',
    password: '***********',
    host: 'imap.gmail.com',
    port: 993, // imap port
    tls: true,
    connTimeout: 10000, // Default by node-imap
    authTimeout: 5000, // Default by node-imap,
    debug: 'off', // debuging
    tlsOptions: { rejectUnauthorized: false },
    mailbox: 'INBOX', // mailbox to monitor
    searchFilter: ['UNSEEN'], // the search filter
    mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
    attachments: true, // searching attachments
    attachmentOptions: { directory: 'attachments',stream:true }, // specify a download directory for attachments, otherwise it will create a directory with the name of 'attachments' in the project directory, if 'attachments:true'
    // to pause for 'fetchingPauseTime' fetching of the email, because it 'hangs' your app
    fetchingPauseThreshold: null, // amount bytes
    fetchingPauseTime: 5000, // ms to pause fetching and process other requests,
    reCheckMode : false, // update mail once again after results found
    dividerBeforeSignature: '<=====================>' // this is the divider, means that discard everything below after this symbol.
  };

Others search criteria

Get unread emails since Jul 21, 2018:

  // using the functions and variables already defined in the first example ..

  searchFilter:[ 'UNSEEN', ['SINCE', 'Jul 21, 2018'] ]

You can set your won custom search criteria in the search filter. Please go through the below reference

  var delay = 24 * 3600 * 1000;
  var previousDay = new Date();
  previousDay.setTime(Date.now() - delay);
  previousDay = previousDay.toISOString(); // 2018-07-20T22:18:40.013Z

  searchFilter:[ 'UNSEEN', ['SINCE', previousDay]]

Attachments

Setting 'attachments: true' means, it will check attachments and will download to the project directory, while parsing emails details, otherwise it will ignore all the attachments. You can also specify for the download directory using the setting of 'attachmentOptions: { directory: 'attachments'}'.

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago