Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: How can I just access the “To”, “Body” and “From” fields of an e-mail received using node-imap?

I'm using node-imap to get my Gmail e-mails and although their example runs pretty well, I'm not being able to only print the msg.To, msg.Body, and msg.From. I can only print the entire message, which is a lot.

Thanks.

like image 518
donald Avatar asked Dec 02 '25 16:12

donald


1 Answers

According to the documentation for node-imap, the To and From headers are available in the msg.headers, which includes the To and From. In order to retrieve the body you must append a variable every time the chunk event is emitted, and upon end you should have a completed body. The headers will probably also not be fully available until the end event has been triggered, so you must take that into account.

like image 140
Bryan Avatar answered Dec 04 '25 05:12

Bryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!