Unable to read email with simpleParser
IrfanSyed-PSC opened this issue · 2 comments
Hello,
I am trying to read an email from IMap and then parse it using simpleParser. As you can see, I am fetching the email, and then getting the stream of the message body. But when I try to parse it to simpleParser(), the function is not executed and it kind of does a return. I thought the stream was invalid and verified if the stream is readable or not and it is readable. I even tried to write the stream to a file and I was successful. So I am not sure why this parser would fail to parse the email message. The email I was trying to read was for gmail. The scary part is that it does not even give any error message. It just get returned from the block and does not even execute my console messages.
Any thoughts ? I am using the latest version of the library.
`const f = imap.fetch(results, { bodies: '', struct: true });
f.on('message', msg => {
msg.on('body', async stream => {
let parsed = await simpleParser(stream);
console.log('my parsed ', + parsed)
simpleParser(stream).then(parsed => {
console.log("success")
}).catch(_err => {
console.log('failure')
})
});
});
`
If you are using node-imap then it is not compatible with await..async. The parser probably throws an error for whatever reason, but it is never caught or shown, as you use an async function as an event handler.
You could try ImapFlow or EmailEngine instead of node-imap if you want async support. Or you could modify your code so that it works properly with async await.
Thank you. Do you have any example for using without async...await. As you can see, even after remove the async, I am getting into issues. So both methods did not work for me.