Code Monkey home page Code Monkey logo

mail-listener2's Introduction

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, mailparser.

Heavily inspired by mail-listener.

Use

Install

npm install mail-listener2

JavaScript Code:

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 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 for specifics on how to stream attachments.

License

MIT

mail-listener2's People

Contributors

amtrack avatar chirag04 avatar collinanderson avatar goldibex avatar jabis avatar jkostrz avatar jorgecuesta avatar jutaz avatar kevireilly avatar miguelzf avatar oblador avatar somename85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mail-listener2's Issues

imapDisconnected always connection getting disconnected.

after uploading to the firebase , i am getting below error in firebase console

Error: getaddrinfo ENOTFOUND imap.gmail.com imap.gmail.com:993
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'imap.gmail.com',
host: 'imap.gmail.com',
port: 993,
source: 'socket'

Attachment flag not working when set to false

Here is my case:

I don't want to save the attachments on my file system (Doing other things with them) so i specified the flag of attachments to false

According to the comment in the example - attachments: true, // download attachments as they are encountered to the project directory I infered that if I give a false value, it's not going to download them.

Even with false value it downloads them.

If you open index.js you can see the problem in the checks:

// line 21
if (options.attachments && options.attachmentOptions && options.attachmentOptions.stream) {
    this.mailParserOptions.streamAttachments = true;
  }

If attachments is false then this.mailParserOptions.streamAttachments will be undefined.

Down below, on parse end, we have the following check:

if (!self.mailParserOptions.streamAttachments && mail.attachments) {

It happens to be if(!undefined && mail.attachments) - !undefined is true and if we have attacments, mail.attachments will be true, so even if I say - don't download attachments via the options, it will download them anyway.

I am not pull requesting the fix since it requires changing 2 lines of code ;)
If you want - I will make a patch.

But first - reproduce the bug!

Streaming Attachments

Is it possible to stream "mail.attachments" that is being returned by the .on("mail") event emitter?

Cannot read property 'bodyEmitter' of undefined

I've been having some issues the listener, where it sometimes gets disconnected.
I've put up a retry mechanism, where upon 'server:disconnected' it retries to connect (.start() command) every 1 minute, but then I see the logs stacked with the following error (seems intermittent):

info: IMAP disconnected, retrying...
info: Restarting IMAP connection. [retries=1]
info: Restarting IMAP connection. [retries=2]
info: Restarting IMAP connection. [retries=3]
info: Restarting IMAP connection. [retries=4]
error: uncaughtException: Cannot read property 'bodyEmitter' of undefined
stack:
[ 'TypeError: Cannot read property 'bodyEmitter' of undefined',
' at Connection._resTagged (../node_modules/mail-listener2/node_modules/imap/lib/Connection.js:1484:10)',
' at Parser. (../node_modules/mail-listener2/node_modules/imap/lib/Connection.js:177:10)',
' at Parser.EventEmitter.emit (events.js:95:17)',
' at Parser._resTagged (../node_modules/mail-listener2/node_modules/imap/lib/Parser.js:175:10)',
' at Parser._parse (../node_modules/mail-listener2/node_modules/imap/lib/Parser.js:139:16)',
' at Parser._tryread (../node_modules/mail-listener2/node_modules/imap/lib/Parser.js:82:15)',
' at CleartextStream.Parser.cbReadable (../node_modules/mail-listener2/node_modules/imap/lib/Parser.js:53:12)',
' at CleartextStream.EventEmitter.emit (events.js:92:17)',
' at emitReadable
(_stream_readable.js:392:10)',
' at _stream_readable.js:385:7' ]

What could cause this? should I be retrying differently? recreate MailListener object?

gmail blocking access

Putting my username and password into the test script fails with the message:

{ [Error: Please log in via your web browser: http://support.google.com/mail/accounts/bin/answer.py?answer=78754 (Failure)] textCode: 'ALERT', source: 'authentication' }

Then I received an email from google:

Hi ********, 

We recently blocked a sign-in attempt to your Google Account [********@gmail.com]. 

Sign in attempt details
Date & Time: Tuesday, September 9, 2014 2:30:15 PM UTC 
Location: New York, USA 

If this wasn't you
Please review your Account Activity page at https://security.google.com/settings/security/activity to see if anything looks suspicious. Whoever tried to sign in to your account knows your password; we recommend that you change it right away. 

If this was you
You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards. 

To learn more, see https://support.google.com/accounts/answer/6010255. 

Sincerely,
The Google Accounts team

Have you been able to use mail-listener2 with gmail? If so, how do I get around the constraint?

authentication failed, email not fetched

It is giving me error like this. I have double check for my username/email and password.
I am getting following error : [Error: Please log in via your web browser: http://support.google.com/mail/accounts/bin/answer.py?answer=78754 (Failure)] textCode: 'ALERT', source: 'authentication' }
imapDisconnected

Should I have to configure my gmail account?

Publish 0.2.0 to npm please

Hi,

I see you added the timeouts to version 0.2.0 could you publish to npm please? It is 0.1.8 currently.

Thanks

Getting from email address in attachments section

Hi,
for downloading the attachments i wrote following piece of code. This is working perfectly fine
But thing is i want to append from email id at the end of each attachment file name at the time of downloading.Something like "attachment.generatedFileName+'___'+fromemailid ". But i am not able to get from email id or even mail object in the attachments event.

Also i thought like as mail processing is sequential, i thought of taking a variable called fromEmail and fill it with the actual value in
mailListener.on("mail", function(mail, seqno, attributes){})

and later make use of it in attachments event. But thing is attachments event is firing first and later mail event is firing.

mailListener.on("attachment", function(attachment){
var validDownloadTypes=['application/pdf','application/msword','text/plain','application/rar','application/zip'];
if(validDownloadTypes.indexOf(attachment.contentType)>=0)
{
console.log("Downloading attachment to --- C:\MailDownloads"+attachment.generatedFileName);
var output = fs.createWriteStream("C:\MailDownloads"+attachment.generatedFileName);
attachment.stream.pipe(output);
}
});

Multiple mail accounts

Hi, can you add a rough / simple example how to listen to multiple mail accounts? :)
//Edit: ok, I figured it out by self.

var data = [
    {'usern': '[email protected]', 'passw': 'bar'},
    {'usern': '[email protected]', 'passw': 'bar'},
    {'usern': '[email protected]', 'passw': 'bar'}
    (...)
];

data.forEach(function (v) {
    var mailListener = new MailListener({
        username: v.usern,
        password: v.passw,
        (...)
   )};
    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);
    });
});

Listen to many accounts in one script

Hello,
I need to create listening for multiple accounts in one script.
Do you have any experience in this?
How to organize code?
Any comments are welcome.

pwldp

Duplication of emails in listener

If I work with a simple UNSEEN flag and use the vanilla example with no changes other than my gmail IMAP information I see the following behaviour.

Start mail-listener2
Go to gmail on web client
Select 3 emails
Mark as unread
Mail-listener2 console will output the same 3 emails 3 times. This creates a total of 9 mails being displayed in the console.

Doubling mail

Hello. When two emails come to my mail at once, this application returns two letters two times. How many letters - so many times all the letters will repeat. How to solve this problem?

TimeOut

How to re-connect when connection timeout

Maildisconnect feature doesn't work.

The mailconnection works properly but it doesn't disconnect from the server properly. This causes the mail_max_userip_connections=10 issue. I am unable to close connection and then after 10 connections from the same ip, the server doesn't allow us to connect.

The actual email subject in my test case is always the same

I've config the mail-listener2 on my Node.JS in order to verify when
automatically email is sent to the user during an automation testing I do by Protractor.

In the first test case the verification of the incoming email subject is good,
but in another test cases is always compare the expected subject result to the first test cases and than they are failed.

BTW, I'm pretty sure that the correct email is sent, I saw it in the log,
probably the problem, is because the variables of "email" "subject" I can't find where they come from..

Please your help!

Thanks!

This is the protractor conf file:

var path = require('path');
var fs = require('fs');
var HtmlReporter = require('protractor-html-screenshot-reporter');
var Imap = require('imap'),
    inspect = require('util').inspect;
var MailParser = require("mailparser").MailParser;
var MailListener = require("mail-listener2");



  getLastEmail = function() {
      var deferred = protractor.promise.defer();
      console.log("Waiting for an email...");

      mailListener.on("mail", function(mail){
          deferred.fulfill(mail);
      });
      return deferred.promise;
    };



  onPrepare: function() {
    // here goes your email connection configuration
    var mailListener = new MailListener({
        username: "[email protected]",
        password: "password",
        host: "imap.gmail.com",
        port: 993, // imap port 
        tls: true,
        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();

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

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

    mailListener.on("mail", function(){
      console.log("GO IT!");
    });

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

    global.mailListener = mailListener;
}, 

  jasmineNodeOpts: {
      onComplete: function () {
      mailListener.stop();
    },
      // If true, display spec names.
      isVerbose: true,
      // If true, print colors to the terminal.
      showColors: true,
      // If true, include stack traces in failures.
      includeStackTrace: true,
      // Default time to wait in ms before a test fails.
      defaultTimeoutInterval: 9999999
  }

}

This is the failed test case:

describe('LiveSite Portal - Client book a new meeting', function() {

    var randomDay = Math.floor(30*Math.random() + 1);
    var randomDayLink = randomDay.toString(); 
    var EC = protractor.ExpectedConditions;

  it('LiveSite - Home Page', function() {
       liveSiteHome();
    });


  it('Client LiveSite Portal - Schedule new meeting > Services screen', function() { 
    element(by.xpath("//div[@class='actions-row']//a[.='Schedule Now']")).click();
    browser.wait(EC.visibilityOf(element(by.css("div.service-info"))), 15000);
    expect (element(by.css("div.service-info")).isPresent()).toBe(true);
    });

  it('Client LiveSite Portal - New Meeting - Multistaff selection screen', function() {  
    element(by.css("div.service-info")).click();
    browser.wait(EC.visibilityOf(element(by.css("ul.staff"))), 15000);
    expect (element(by.css("ul.staff")).isPresent()).toBe(true);
   });

  it('Client LiveSite Portal - New Meeting - Date picker', function() {  
    element(by.css("ul.staff")).click();
    browser.wait(EC.visibilityOf(element(by.css(".slots"))), 15000);
    expect(element(by.css(".slots")).isPresent()).toBe(true);
  });

  it('Client LiveSite Portal - New Meeting - Booking meeting', function() {  
    element(by.linkText("Next")).click();
    browser.driver.sleep(5000);
    element(by.linkText(randomDayLink)).click();
    browser.wait(EC.visibilityOf(element(by.xpath("//ul[@class='column-2']/li[2]/a/div"))), 15000);
    element(by.xpath("//ul[@class='column-2']/li[2]/a/div")).click();
    browser.wait(EC.visibilityOf(element(by.linkText("Continue"))), 15000);
    element(by.linkText("Continue")).click();
    browser.wait(EC.visibilityOf(element(by.model("meeting[field.attribute_name]"))), 15000);
    expect(element(by.model("meeting[field.attribute_name]")).isPresent()).toBe(true);
 });

  it('Client LiveSite Portal - New Meeting - Client Info', function() {   
    element(by.id("client_phone")) .sendKeys("0556783242")    
    element(by.name("email")).sendKeys("[email protected]");
    element(by.id("terms_of_service")).click();
    element(by.xpath("(//textarea[@id='agenda'])[2]")).sendKeys("hello again");
    element(by.linkText("Submit")).click();
    browser.wait(EC.visibilityOf(element(by.css("a.standard-button"))), 15000);
    expect (element(by.css("a.standard-button")).isPresent()).toBe(true);
  });

  it('Client LiveSite Portal - New Meeting - Email has been sent to the business side', function() {
    browser.driver.controlFlow().await(getLastEmail()).then(function (email) {
      expect(email.subject).toContain("Appointment scheduled with");
    });
  });

  it('Client LiveSite Portal - New Meeting - Appointmend has been scheduled', function() {   
    element(by.linkText("Done")).click();
    waitPageToLoad();
    expect(element(by.model("email")).isPresent()).toBe(true);
  });

});

This is the error:

Error: Expected 'New document shared by vCita idan' to contain 'Appointment scheduled with'. at new jasmine.ExpectationResult (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:137:32) at [object Object]. (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1349:29) at [object Object].toContain (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:248:11) at c:\automation\tests\meeting.js:54:29 at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.Callback_.goog.defineClass.notify (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2464:25) at [object Object].promise.Promise.notify_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:563:12) at Array.forEach (native) at Object.goog.array.forEach (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\array\array.js:203:43) at [object Object].promise.Promise.notifyAll_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:552:16)

More docs?

It would be great to have docs on things such as the available filters to be used in searchFilter, and the construction of the mail object that is returned ,or at least a link to where these docs exist.

timeout-auth error with outlook.office365.com

var mailListener = new MailListener({
username:'email here',
password:'pass here',
host:'outlook.office365.com',
port:995,
tls: true,
tlsOptions: {rejectUnauthorized: false},
mailbox: 'INBOX',
searchFilter: ['UNSEEN'],
markSeen: true,
fetchUnreadOnStart: true,
mailParserOptions: {streamAttachments: true},
attachments: false,
attachmentOptions:{directory: 'attachments/'}
});

Leads to following error
{ [Error: Timed out while authenticating with server] source: 'timeout-auth' }
imapDisconnected

Found a similar thread reporting the same error here.
https://community.office365.com/en-us/f/172/t/235791

How do I increase the timeout?

Urgent help needed.

Thanks

watch multiple mailboxes

I tried to modify the script so it could watch more than one mailbox (e.g sub-folders) for incoming mails. This is not quite as easy as it seems due to the limitations of node-imap (only one mailbox per connection (the heck..)). I actually do have some attempts but before I do implement them I'd like to ask you for your opinion. How would you solve it? With multiple connections? Switch the boxes in a defined interval?

Read timeout: how to debug?

I'm continuously getting an Error: read ETIMEDOUT, but I have no idea as how to go about debugging it. Using gmail IMAP as service. Any ideas?

Multiple Instances

This is off topic but still little help would be appreciated.

We are running multiple Beanstalk instances of our app and the imap listener(of all instances) fire when a new mail arrives.

This is resulting in a race condition.

Ideally, we want load balancing to get in action.

Any thoughts ?

Saving attachment fail

If you are using {streamAttachments: true} for the mailParserOptions, then you will get the stream of the attachment without file buffer. So then you cannot save the attachment with fs.writeStream, and must use attachment.stream.pipe(filename) as in the mailparser documentation (not work for me, actually). So may be solution is do not use {streamAttachments: true} in documentation.

Thanks

Missing autotls option

Hi,

What about the autotls : 'required'/'always' option, which is present in node-imap, but not in mail-listener2 ? Is there any way to handle it ?

Edit: Would it be wrong to add a simple handling for autotls in this library ? Manually adding autotls: 'required' works like a charm, so it shouldn't be harmful.

Unable to connect on office 365 using imap protocol

HI,

I'm using office 365 address to parse email using IMAP protocol. Our parser works by connecting with the EMAIL box ( using imap protocol) and parse the incoming email and mark them read. We have a huge user base and we normally get around 4k emails per day. All the emails are parsed and are available in the inbox.

From last few days ( Friday 25th 2014) our parser stopped parsing email as it was unable to connect with IMAP server(office 365 exchange server).

I'm receiving the following error.

Error Found while connecting IMAP : { [Error: Command Error. 10] textCode: undefined, source: 'protocol' }

Error Found while connecting IMAP : { [Error: write ECONNRESET]

code: 'ECONNRESET',

errno: 'ECONNRESET',

syscall: 'write',

source: 'socket' }

Error Found while connecting IMAP : { [Error: Timed out while authenticating with server] source: 'timeout-auth' }.

i'm using Nodejs and mail-listener2(https://github.com/chirag04/mail-listener2) for parsing.

Any help in this regards would be appreciated.

Thanks,

Waqas Ahmed

No activity

Maybe I am missing something, but using both a google apps for business account and personal gmail account, noting happens. I have sent probably 20 emails to and from each of these accounts and nothing is ever picked up. All i get is "imapConnected". Any suggestions?

Output is not generated.

Hi,
I used the below snippet. Although it does not return any error but it does not produce any output. I think the code from line mailListener.on does not execute (Please help.!!!
var MailListener = require("mail-listener2");

	 var mailListener = new MailListener({
	   username: "[email protected]",
	   password: "test",
	   host: "imap.gmail.com",
	   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"],
	   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/" }
	 });
	  
	 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 
	 });

{ [Error: No supported authentication method(s) available. Unable to login.] source: 'authentication' }

I am getting this error when i try to connect with zoho mail using mail-listener2, But i can able to connect and read mail from my application using node-imap. Please help me on this issue.

The config param i am using with node-imap is as below

var imap = new Imap({
user: nconf.get('IMAP_USER'),
password: nconf.get('IMAP_PASS'),
host: nconf.get('IMAP_HOST'),
port: nconf.get('IMAP_PORT'),
connTimeout: 10000000,
tls: true
});

Same param i am using with mail-listener2 but getting the below error

{ [Error: No supported authentication method(s) available. Unable to login.] source: 'authentication' }

Mail listener crashing on attachment

I did not try with other OS, but on windows 8, when i send a file with attachment, mail listener crashes even when event to handle attachments is handled. I tried all options of streaming, directory and handling attachment. Any help is appreciated.

reading mail sequentially

is there a property to set that enables to read mail sequentially,so that one can perform set of operation on after reading one mail and then move on to next ,
i think we can use seq no for this in any way , just a question

Please add "mail" param for attachments.

https://github.com/andris9/mailparser#attachment-streaming

mp.on("attachment", function(attachment, mail){
    var output = fs.createWriteStream(attachment.generatedFileName);
    attachment.stream.pipe(output);
});

https://github.com/chirag04/mail-listener2/blob/master/index.js#L115 ๐Ÿ˜ƒ

Now:

parser.on("attachment", function (attachment) {
    self.emit('attachment', attachment);
});

Need:

parser.on("attachment", function (attachment,mail) {
    self.emit('attachment', attachment, mail);
});

Listener disconnects

We are using Gmail(IMAP) to listen for emails in our application and it seems the listener disconnects at times.

Can you tell me what could the reason be if it has to do with code ?

We are listening for all events and our main application does not crash, only the listener disconnects.

Plus, if there a way to reconnect ? Sort of a container I can run listener inside that makes sure it reconnects when it disconnects ?

How to listen only the latest?

When i do a console.log which prints all my unread emails console.log(mail.headers['from'])

How do i change so that it only grab the latest or first item of the index?

xlsx/xls attachments

I'm having trouble parsing excel spreadsheets - would you be able to provide a best practice example of how to deal with an email that has an xls attachment?

rejectUnauthorized

Thanks man for re-writing the lib!
I tried using it and I'm getting imapdisconnected.

my assumption is it's about tlsOptions: { rejectUnauthorized: false }, did you add that to the lib?

Update: just checked and it's not reject Unauthorized. but still I'm not getting any details on why it's always disconnected.

How to set proxy?

Try to use mail-listener2 under a proxy, but got Error: Timed out while connecting to server

imap disconnected every few hours

Is there a way to prolong the life of the mail listener connection without having to refresh the code every few hours? I notice that the mail listener disconnects after a while of no traffic.

Thanks

Changelog

Can you create "Releases" with changelog. You update version, but without see changes in commitns not know what was changed...
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.