Gmail Setup Guide¶
This guide walks through setting up Gmail as a chat provider in AgentComms.
Overview¶
AgentComms uses the Gmail API with OAuth 2.0 for authentication. This allows sending emails programmatically from your Gmail account without needing to enable "less secure apps" or use app-specific passwords.
Prerequisites¶
- A Google account
- Access to Google Cloud Console
Step 1: Create a Google Cloud Project¶
- Go to Google Cloud Console
- Click "Select a project" dropdown at the top
- Click "New Project"
- Enter a project name (e.g., "AgentComms")
- Click "Create"
Step 2: Enable the Gmail API¶
- In the Cloud Console, go to APIs & Services > Library
- Search for "Gmail API"
- Click on "Gmail API"
- Click Enable
Step 3: Configure OAuth Consent Screen¶
- Go to APIs & Services > OAuth consent screen
- Select External (or Internal if using Google Workspace)
- Click Create
- Fill in the required fields:
- App name: AgentComms
- User support email: Your email
- Developer contact email: Your email
- Click Save and Continue
- On the "Scopes" page, click Add or Remove Scopes
- Find and select
https://www.googleapis.com/auth/gmail.send - Click Update, then Save and Continue
- Add yourself as a test user (required for external apps in testing)
- Click Save and Continue, then Back to Dashboard
Step 4: Create OAuth Credentials¶
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Desktop app as the application type
- Enter a name (e.g., "AgentComms CLI")
- Click Create
- Click Download JSON to download your credentials
- Save the file as
~/.agentcomms/gmail_credentials.json
Step 5: Configure AgentComms¶
Option A: Environment Variables¶
# Enable Gmail
export AGENTCOMMS_GMAIL_ENABLED=true
# Path to credentials file (required)
export AGENTCOMMS_GMAIL_CREDENTIALS_FILE=~/.agentcomms/gmail_credentials.json
# Path to store OAuth token (optional, defaults to ~/.agentcomms/gmail_token.json)
export AGENTCOMMS_GMAIL_TOKEN_FILE=~/.agentcomms/gmail_token.json
# From address (optional, defaults to "me" for authenticated user)
export AGENTCOMMS_GMAIL_FROM_ADDRESS=me
Option B: JSON Configuration¶
Add to ~/.agentcomms/config.json:
{
"chat": {
"gmail": {
"enabled": true,
"credentials_file": "${HOME}/.agentcomms/gmail_credentials.json",
"token_file": "${HOME}/.agentcomms/gmail_token.json",
"from_address": "me"
}
}
}
Step 6: Authorize the Application¶
On first run, AgentComms will open a browser window for OAuth authorization:
- Start AgentComms:
agentcomms daemon - A browser window opens to Google's OAuth consent screen
- Sign in with your Google account
- Review the permissions and click Allow
- The browser shows "Authorization successful" and you can close it
- AgentComms stores the token in your token file
After authorization, AgentComms won't need browser access again unless the token expires or is revoked.
Usage¶
Sending Emails via MCP¶
{
"tool": "send_message",
"arguments": {
"provider": "gmail",
"chat_id": "recipient@example.com",
"content": "Hello from AgentComms!",
"metadata": {
"subject": "Test Email"
}
}
}
Email Subject¶
The email subject can be set in several ways:
-
Metadata field (recommended):
-
First line of content: If no subject is provided, the first line of the content is used
-
Default: Falls back to "Message from AgentComms"
HTML Emails¶
Set the format to HTML for rich content:
{
"tool": "send_message",
"arguments": {
"provider": "gmail",
"chat_id": "recipient@example.com",
"content": "<h1>Hello</h1><p>This is <strong>HTML</strong> content.</p>",
"format": "html",
"metadata": {
"subject": "HTML Test"
}
}
}
Troubleshooting¶
"Access blocked: AgentComms has not completed the Google verification process"¶
This is normal for apps in testing mode. Solutions:
- Add your email as a test user in OAuth consent screen
- Or publish the app (requires verification for broader access)
"Token has been expired or revoked"¶
Delete the token file and re-authorize:
"Missing required environment variables"¶
Ensure AGENTCOMMS_GMAIL_CREDENTIALS_FILE points to a valid credentials JSON file.
"Failed to read Gmail credentials file"¶
Check that the file exists and is readable:
The file should contain JSON with installed or web key containing client_id and client_secret.
Security Notes¶
-
Never commit credentials: Add
gmail_credentials.jsonandgmail_token.jsonto.gitignore -
Token storage: The OAuth token file contains refresh tokens. Protect it like a password.
-
Scope limitation: AgentComms only requests
gmail.sendscope, which cannot read your emails. -
Revoke access: You can revoke AgentComms access at any time from Google Account Security.
API Quotas¶
Gmail API has usage limits:
| Quota | Limit |
|---|---|
| Messages sent per day | 500 (personal), 2000 (Workspace) |
| Requests per minute | 250 |
For higher limits, consider using a Google Workspace account.