{"id":24266826,"url":"https://github.com/brunofbarbosa/java-gmail-integration","last_synced_at":"2025-07-10T07:33:18.199Z","repository":{"id":194780252,"uuid":"691542677","full_name":"BrunoFBarbosa/java-gmail-integration","owner":"BrunoFBarbosa","description":"Java Application for retrieving Gmail emails via IMAP","archived":false,"fork":false,"pushed_at":"2023-09-14T13:12:00.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T01:42:15.397Z","etag":null,"topics":["gmail","imap","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrunoFBarbosa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-14T11:49:30.000Z","updated_at":"2024-12-29T13:36:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"53b63d0d-f21c-4b65-ba64-f037b942a8f6","html_url":"https://github.com/BrunoFBarbosa/java-gmail-integration","commit_stats":null,"previous_names":["brunofbarbosa/java-gmail-integration"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BrunoFBarbosa/java-gmail-integration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoFBarbosa%2Fjava-gmail-integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoFBarbosa%2Fjava-gmail-integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoFBarbosa%2Fjava-gmail-integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoFBarbosa%2Fjava-gmail-integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrunoFBarbosa","download_url":"https://codeload.github.com/BrunoFBarbosa/java-gmail-integration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrunoFBarbosa%2Fjava-gmail-integration/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264545169,"owners_count":23625404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gmail","imap","java"],"created_at":"2025-01-15T11:28:01.625Z","updated_at":"2025-07-10T07:33:17.902Z","avatar_url":"https://github.com/BrunoFBarbosa.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About the Project\n\nA Java Application for retrieving Gmail emails content via IMAP using JavaMail.\n\nThis application will search the Inbox folder for an email given a subject. If found, it will mark the email as read and delete it.\n\n## Getting Started\n\n### Prerequisites\n- OpenJDK 17+\n- Apache Maven 3.9.3+\n- A Gmail account\n- An OAuth2 access token\n\n### Getting the OAuth2 token\n In order to get an OAuth2 token, you will need to configure a Google project on Google developer's console. A detailed step and instructions can be found [here](http://code.google.com/apis/accounts/docs/OAuth2.html).\n In particular, you will need the Client ID, the Client secret and the refresh token.\n\n A very easy way to obtain the refresh token is using the tool [OAuth2DotPyRunThrough](https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough).\n \n After getting the refresh token, the Access token can be obtained and updated by performing a POST request to the endpoint https://oauth2.googleapis.com/token with the parameters ```client_id```, ```client_secret```, ```grant_type``` and the ```refresh_token```.\n \n E.g:\n\n```\ncurl --location --request POST 'https://oauth2.googleapis.com/token?client_id=GOOGLE_CLIENT_ID\u0026client_secret=GOOGLE_CLIENT_SECRET\u0026grant_type=refresh_token\u0026refresh_token=REFRESH_TOKEN'\n```\n### Notes\n\n- It is worth mention that the Access token will only last 1h. After that period you will need to make a new POST request to get a new one.\n\n- From the Google [documentation](https://developers.google.com/identity/protocols/oauth2#expiration) the refresh token will expire in 7 days if the Google project is set to \"Testing\". So, if you want the token to never expire, you can change your App status to \"Published\".\n\n## Running the project\n\nAfter getting the necessary tokens, you will need yo update the file ```api.properties``` to use them:\n\n```\nGoogleApiUri=https://oauth2.googleapis.com\nClientGoogleId=YOUR_GOOGLE_CLIENT_ID\nClientGoogleSecret=YOUR_GOOGLE_CLIENT_SECRET\nClientGoogleRefreshToken=YOUR_GOOGLE_REFRESH_TOKEN\n```\nThere is a ```EmailExample.java``` class that can be used to validate if everything is set correctly, you just need to update the ```YOUR_EMAIL``` and ```EMAIL_SUBJECT``` constants to reflect the ones you want.\n\nE.g:\n\nThis will search the Inbox folder from the email \"myemail@gmail.com\" that contains the subject \"My Email Subject\". Assuming \"myemail@gmail.com\" is the account that the Google project was set on, it should print the contents of the email.\n\n```\npackage com.email.example.main;\n\nimport com.email.example.support.email.gmail.ImapGmailEmailClient;\nimport com.email.example.support.helpers.EmailHelper;\nimport com.email.example.support.email.EmailClient;\n\npublic class EmailExample {\n    public static void main(String[] args) throws InterruptedException {\n        EmailClient imapGmailEmailClient = new ImapGmailEmailClient(\"myemail@gmail.com\");\n        String content = new EmailHelper(imapGmailEmailClient).getEmailContents(\"My email Subject\");\n        System.out.println(content);\n    }\n}\n```\n\n## References\n- [JavaMail Documentation](https://javaee.github.io/javamail/OAuth2)\n- [Google Documentation](https://developers.google.com/identity/protocols/oauth2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunofbarbosa%2Fjava-gmail-integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunofbarbosa%2Fjava-gmail-integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunofbarbosa%2Fjava-gmail-integration/lists"}