Search code examples
javagmailgmail-api

Retrive a mail from gmail inbox for a particular subject


I have a scenario where I have to read a mail sent out by a X person with a specific subject, which i will be receiving on a daily basis.

Is there any JAVA Gmail APi provided by google to retrieve the recent mail that i have received.

And also is there a way to retrieve the mail for a given date?


Solution

  • Yes there's a Gmail API and it has a Java client library, you can check the Quickstart to get used to it.

    Now, for retrieving a list of mails you will need to use the Users.messages: list endpoint ( There's also a Java example on how to use that endpoint). Answering your question about retrieving certain emails, you will need to use the q parameter and set the values there as if you would be searching an email in the gmail search bar. I will leave you an example that you can try using the Try this API:

    Notice

    You will only get the email's IDs, for getting more info about an email, you will have to use the Users.messages: get endpoint.