imap-riyo
v1.0.16
Published
Email Parsing
Downloads
6
Readme
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: '[email protected]',
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": "[email protected]",
"name": "Test developer"
}
],
"to": [
{
"address": "[email protected]",
"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: '[email protected]',
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'}'.