Can anybody help me out in this? I'm working with gmail-api where I need to read a email. I have gone through the documentation of Gmail API for reading a messages, and I'm able to read email into RFC format. How do I convert it to normal Text?
If at all I need to use Java Libraries Mime classes for conversion, how do I use it specifically to read "From address", "To address" and "Message Body?"
Once you have a raw (RFC822) email string you can use the java MimeMessage
library to parse it and then read the headers. I found a couple by searching for java MimeMessage example
. You can use the MimeMessage(Session, InputStream)
constructor, once you have a MimeMessage
you can just call things like getFrom()
or getHeader(String headerName)
on it.
While not exactly what you're trying to do, the Gmail API java guide for sending email is somewhat relevant in that it shows how to deal with MimeMessage libraries, etc: