'Getting attachments with mail-listener2

https://github.com/chirag04/mail-listener2 works great for getting new emails, but the attachments option isn't working for me. on.('attachment'...) never fires.

Using:

var mailListener = new MailListener({
    // ... connection options
    mailParserOptions: { streamAttachments: true }, 
    attachments: true, 
    attachmentOptions: {
        directory: path.join(__dirname, 'attachments'),
        stream: "true"
    }, 
});

// ...

mailListener.on("attachment", function (attachment) {
    console.log(attachment.path);
});

Also tried adding (from Mail Parser docs)

mailListener.on('data', data => {
    console.log(data)
    if (data.type === 'attachment') {
         console.log(data.filename);
         data.content.pipe(process.stdout);
         data.content.on('end', () => data.release());
    }
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source