A Step-by-Step Guide to Setting Up and Integrating Google Mailboxes Using OAuth2
Introduction
This guide provides a detailed process to connect Google mailboxes with Warmy using OAuth2. By following these steps, you can securely authenticate, manage, and optimize email deliverability through Warmy’s API integration.
Required Data for Connection
To integrate mailboxes with Warmy, you need the following data:
- client_id: Unique identifier for the application created in Google Cloud Console.
- client_secret: The secret key of the application (used for server-side integrations only).
- access_token: Token to interact with the API.
- refresh_token: Token to refresh the
access_token
after expiration. - expires_at: The expiration time of the
access_token
(in seconds since the Unix Epoch). - redirect_uri: The URL to which the user is redirected after authentication.
- token_credential_uri: URL for obtaining tokens.
Integration Example
Here’s how to integrate Google mailboxes with Warmy.io using the API:
curl --location 'https://api.warmy.io/api/v2/mailboxes' \
--header 'client;' \
--header 'access-token;' \
--header 'uid;' \
--header 'holder-uid: a66a9a755fe16f24fcb99dc8b5f25a50' \
--header 'Content-Type: application/json' \
--data-raw '{
"mailbox": {
"provider": "oauth_google",
"from_name": ""your_from_name_here",
"email": "your_email_here",
"client_id":"your_client_id_here",
"client_secret":"your_client_secret_here",
"access_token":"your_access_token_here",
"expires_at": 1729259022,
"redirect_uri":"your_redirect_uri_here",
"token_credential_uri":"https://oauth2.googleapis.com/token",
"refresh_token":"your_refresh_token_here",
"tariff_plan_type_id": 1,
"setting_attributes": {
"speed_mode": "fast"
}
}
}'
Getting Data by Registering an Application in the Google Cloud Console
1. Registering an Application in Google Cloud Console
- Go to the Google Cloud Console: console.cloud.google.com.
- Create a New Project:
- Click New Project.
- Enter the project name and select an organization.
- Click Create.
- Enable the Gmail API:
- Navigate to API & Services > Enabled APIs & Services.
- Click Enable APIs and Services.
- Search for Gmail API and click Enable.
2. Configuring OAuth Consent Screen and Scopes
- Navigate to API & Services > Credentials and click Create Credentials > OAuth 2.0 Client IDs.
- Configure the OAuth Consent Screen:
- Select External.
- Enter the application name, domain, and contact information.
- Add the required scopes (e.g.,
https://mail.google.com/
) to the list. - Click Save and continue
-
Go through Test users:
-
Add the test accounts (your email or other users, if necessary). Click Save and continue
-
-
At the Summary step, check the configuration and click Back to Dashboard, if everything is correct.
-
Publish App (for External users):
-
If the app is ready to be published to all users, click Publish App on the OAuth Consent Screen page.
-
3. Retrieving client_id
and client_secret
-
Navigate to API & Services > Credentials.
-
Click Create Credentials > OAuth client ID.
-
Fill in the following details:
- Application type: Web application.
- Authorized JavaScript origins: Add a valid URI.
- Authorized redirect URIs: Add a URI (e.g.,
https://yourapp.com/oauth-callback
). - Click Create
-
After creating, a pop-up will display the
client_id
andclient_secret
.
⚠️ Save client_secret
as it will not be visible again
OAuth2 Token Generation
Step 1: Receiving auth_code
Need to visit the following URL to receive the authorization code:
https://accounts.google.com/o/oauth2/v2/auth?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&scope={scopes}&access_type=offline
Request Parameters
Pass the following parameters to the URL via the query string:
Parameter | Description |
---|---|
client_id |
The application identifier obtained during registration in the Google Cloud Console |
response_type |
Specifies the type of response expected from the authorization server. Use code to request an authorization code |
redirect_uri |
URL to redirect after successful authorization (must match the setting in the application) |
scope |
The required API permissions (for example, https://mail.google.com/ for Gmail access). |
access_type |
Set to offline to receive refresh_token . |
After visiting this URL, you will be prompted to grant access to your Google account. Once granted, Google will redirect the user to the specified redirect_uri
with the authorization code (auth_code
) in the URL, which can be used to obtain the access token.
Step 2: Exchanging auth_code
for access_token
Send a POST request:
https://oauth2.googleapis.com/token
Request Parameters:
client_id={client_id}
client_secret={client_secret}
code={authorization_code}
redirect_uri={redirect_uri}
grant_type=authorization_code
The successful response will include:
access_token
: Used to authorize API requests.refresh_token
: Used to refresh theaccess_token
.expires_in
: The lifetime of theaccess_token
in seconds.
Step 3: Update access_token
(if necessary)
Send a POST request to the same endpoint:
https://oauth2.googleapis.com/token
Request parameters:
client_id={client_id} &client_secret={client_secret} &refresh_token={refresh_token} &grant_type=refresh_token
Common Errors and Solutions
Error | Solution |
---|---|
Invalid redirect URI | Ensure the redirect_uri matches the one registered in Google Cloud Console. |
Invalid client secret | Verify that you’re using a valid client_secret . |
Problems with expires_in |
After getting theaccess_token , the request to the Warmy V2 API should be made without modifying the expires_in parameter. Send this value in seconds exactly as received from Google. |
Incorrect expires_at |
The expires_at parameter should be the number of seconds since the Unix Epoch (1970-1-1 00:00:00 UTC). For example: 'expires_at": 1729259022. |
Conclusion
This article provides a detailed walkthrough of connecting Google mailboxes with Warmy via API using OAuth2 authentication. By following these steps, you can ensure secure mailbox integration while maintaining email deliverability and optimization for your campaigns.