简体   繁体   中英

Gmail API ? how to request for an email using Gmail api with format of raw and how to convert it into normal String

Can anybody help me out in this? I'm working with 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:

https://developers.google.com/gmail/api/guides/sending

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM