How to Configure OAuth 2.0 Authentication for Gmail

This section provides information about how to configure OAuth 2.0 authentication for Gmail.

Note: You need to create a project in Gmail to support SMTP authentication using OAuth 2.0.

Follow these steps:

  1. Sign into the Google Cloud Console.
  2. To create a project, click Select a project.
  3. On the Select a project dialog, click NEW PROJECT.
  4. On the New Project page, type the project name, and then click CREATE.
  5. Note: If you want to edit project ID, click EDIT. You cannot change the project ID later.
  6. After the project is created successfully, select the project from the Select a project drop-down list or from the Notifications icon on the top-right corner.
  7. Go to the navigation menu on the top-left corner, and then navigate to APIs & Services > Credentials.
  8. On the Credentials page, click CREATE CREDENTIALS, and then select OAuth client ID.
  9. On the Create OAuth client ID page, click CONFIGURE CONSENT SCREEN.
  10. On the OAuth consent screen, select External, and then click CREATE.
  11. The Edit app registration page appears.
  12. On the OAuth consent screen tab, do the following, and then click SAVE AND CONTINUE:
    1. Under App Information, type a name for the application.
    2. From the User support email drop-down list, select the email address.
    3. Under Developer contact information, provide the email address (s) as needed.
    4. Note: In case of any changes to your project, Google sends a notification to the email address (s) that you have provided.
  13. On the Scopes tab, click SAVE AND CONTINUE.
  14. On the Test users tab, do the following, and then click SAVE AND CONTINUE:
    1. Click ADD USERS.
    2. On the Add users dialog, click the empty field, and then select the email address (s) as needed.
    3. The added email address appears in the User information column under Filter table.
  15. On the Summary tab, verify the details, and then do one of the following:
  16. Navigate to APIs & Services > Credentials > CREATE CREDENTIALS, and then select OAuth client ID.
  17. On the Create OAuth client ID page, do the following, and then click CREATE:
    1. From the Application type drop-down list, select Web application.
    2. For Name, type a name for your OAuth 2.0 client.
    3. For Authorized redirect URIs, specify the following redirect URIs:
    4. Note: Configure the redirect URIs based on the domain name and port used for logging in.
  18. After the OAuth client is created successfully, the OAuth client created dialog appears and displays the client ID and client secret for your project.
  19. Notes:
  20. Click OK to close the dialog.
  21. From the left pane, select Enabled APIs & services, and then click ENABLE APIS & SERVICES.
  22. The Welcome to the API Library page appears.
  23. Search for Gmail API in the search bar, and then click Gmail API.
  24. On the Gmail API page, click Enable.
  25. After configuring the project as mentioned in the above steps, go to UDP application, and then navigate to settings > Email and Alert Configuration. To configure email alerts, see How to Configure Email and Alert.

The OAuth 2.0 authentication is configured successfully for Gmail.