2

I'm trying to read gmail message using GmailAPI. I successfully got the message object.

I've the object com.google.api.services.gmail.model.Message and its .toString() resulting {"id":"157433a7e******","threadId":"157433a7e******"}

But i'm unable to read the contents of the object message.getPayload() is returning null, .getSnippet() is returning null, .getRaw() is also returning null

Object API : https://developers.google.com/resources/api-libraries/documentation/gmail/v1/java/latest/com/google/api/services/gmail/model/Message.html

I've tried other ways as mentioned in

How to get full message body in Gmail?

I want to know the mail subject, dates, sender, label, body

Can some one gives me any pointer?

This is the project source I'm using

com.google.api-client %% google-api-client %% 1.22.0

com.google.oauth-client %% google-oauth-client-jetty %% 1.22.0

com.google.apis %% google-api-services-gmail %% v1-rev48-1.22.0

Thanks In Advance

Community
  • 1
  • 1
anji_rajesh
  • 369
  • 2
  • 11

1 Answers1

3

If you try the API Explorer for listing messages, you will see that the response only contains an id of the message and a threadId. You have to make an additional request to get the content of the message.

Message test = service.users().messages().get("me", "157433a7e******").setFormat("full").execute();

Then you just have to get the fields from the message and traverse the parts to get the content of the message.

Community
  • 1
  • 1
Tholle
  • 108,070
  • 19
  • 198
  • 189