How can I get the mail_object.text
results from simpleParser
, and then add it to an array? This array is later returned in a json response.
https://nodemailer.com/extras/mailparser/#simpleparser
Here is my code:
app.get('/', (req, res) => {
//...query code
//parse
mail = [];
for (var i=0; i<result.length; i++) {
simpleParser(result[i].mail.toString('utf8')).then(function(mail_object)
{
console.log("Text body:", mail_object.text);
}).catch(function(err) {
console.log('An error occurred:', err.message);
});
mail.push({id: result[i].mail_id,
body: //mail_object.text - add text body
});
}
res.json(mail);
}