Search code examples
javarestemailgmail-api

Download Emails from Gmail With Contents


I want to download all emails with content. I got the REST API to get all emails but it returns only id and threadId, not other fields like labels, recipients, etc.

Get all email - https://www.googleapis.com/gmail/v1/users/<email-id>/messages/

There is separate api to get all content but it works for single mail. So if I have 100 emails and I get content one by one it will be very slow.

Get content of email - https://www.googleapis.com/gmail/v1/users/<email-id>/messages/<id>

Let me know what is the best way to list emails with contents.


Solution

  • The Gmail API supports Batch requests

    This allows you to get all your messages in batch rather than 1 by 1.

    Here is a sample on how to incorporate it in Java.