mail-listener2 icon indicating copy to clipboard operation
mail-listener2 copied to clipboard

Saving attachment fail

Open Evgeny- opened this issue 9 years ago • 2 comments

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

Evgeny- avatar Apr 15 '15 12:04 Evgeny-

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

gaurav341 avatar May 31 '15 18:05 gaurav341

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

Evgeny- avatar Jun 01 '15 15:06 Evgeny-