chirag04 / mail-listener2

Mail listener library for node.js. Get notification when new email arrived.
MIT License
245 stars 116 forks source link

Saving attachment fail #39

Open Evgeny- opened 9 years ago

Evgeny- commented 9 years ago

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

gaurav341 commented 9 years ago

Hi Evgeny,

I've facing same problem. Unable to download attachments from mail. using your approach only blank file with 0 kb downloaded. Please help

Thanks

Evgeny- commented 9 years ago

Hi Gaurav,

I have using options like this:

{
   ...,
   mailParserOptions: {streamAttachments: false}, 
   attachments: false, 
   attachmentOptions: { directory: "attachments/" } 
}

And then saving attachments directly:

mail.on("mail", function(mail, seqno, attributes) {
   if(mail.attachments && mail.attachments.length) {
      var attach = mail.attachments[0];
      fs.writeFile('file', attach.content, function(err) {
        // callback
      });
   }
});

I hope this will help