OAuth 2.0 Libraries and Samples
Stay organized with collections
Save and categorize content based on your preferences.
The following libraries and samples make it easy to get started using OAuth 2.0
authorization to access the Gmail IMAP and SMTP services.
Java Sample
JavaMail 1.5.2 or later natively supports OAuth for IMAP.
If you need to use an older version, or create your own implementation, see the
Java sample code.
To download the sample, refer to
Tools and sample code for authenticating to Gmail with OAuth2.
Python Sample
PHP Sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-28 UTC.
[null,null,["Last updated 2025-08-28 UTC."],[],[],null,["# OAuth 2.0 Libraries and Samples\n\nThe following libraries and samples make it easy to get started using OAuth 2.0\nauthorization to access the Gmail IMAP and SMTP services.\n\nJava Sample\n-----------\n\nJavaMail 1.5.2 or later [natively supports OAuth for IMAP](https://javaee.github.io/javamail/OAuth2).\nIf you need to use an older version, or create your own implementation, see the\n[Java sample code](https://github.com/google/gmail-oauth2-tools/wiki/JavaSampleCode).\nTo download the sample, refer to\n[Tools and sample code for authenticating to Gmail with OAuth2](https://github.com/google/gmail-oauth2-tools).\n\nPython Sample\n-------------\n\n- [Getting Started](https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough)\n- [Download](https://raw.githubusercontent.com/google/gmail-oauth2-tools/master/python/oauth2.py)\n\nPHP Sample\n----------\n\n- [Getting Started](https://github.com/google/gmail-oauth2-tools/wiki/PhpSampleCode)\n- [Download](https://github.com/google/gmail-oauth2-tools/blob/master/php/oauth2.php)"]]