如何从mail_object.text
获得simpleParser
的结果,然后将其添加到数组中?稍后在json响应中返回此数组。
https://nodemailer.com/extras/mailparser/#simpleparser
这是我的代码:
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);
}