gmail-proxy
Skill0 starsChanged 4 months agoMITView on GitHub
Build Gmail/Calendar integration via a REST proxy instead of implementing OAuth in your frontend. Why this pattern? - Proxy handles OAuth, token refresh, multiple accounts - Frontend just makes simple REST calls with API key - One source of truth for Google API access - No token storage in frontend Environment variables needed: - API_KEY - Your API key for auth - GOOGLE_CLIENT_ID - OAuth client ID - GOOGLE_CLIENT_SECRET - OAuth client secret - TOKENS_PERSONAL - JSON tokens for personal…
- Reads credentials
- Sends data out
In this repository37 other files it gives its agents.
- .agents/skills/vercel-composition-patterns/AGENTS.mdAGENTS.md
- vercel-composition-patterns/AGENTS.mdAGENTS.md
- senior-frontendSkill
- vercel-composition-patternsSkill
- bento-designSkill
- fanned-cardsSkill
- flip-cardSkill
- floating-quotesSkill
- githubSkill
- glassmorphism-uiSkill
- googleSkill
- hippocampusSkill
- html-pdf-exportSkill
- iframe-previewSkill
- infinite-canvasSkill
- matrix-textSkill
- nextjs-apiSkill
- nextjs-expertSkill
- pinterestSkill
- railway-deploySkill
- remotion-videoSkill
- scramble-textSkill
- scroll-video-heroSkill
- senior-frontendSkill
- SEOSkill
- ship-websiteSkill
- sound-engineSkill
- stripe-best-practicesSkill
- tilt-cardSkill
- tube-summarySkill
- upload-postSkill
- vercel-composition-patternsSkill
- vercel-deploySkill
- vercel-react-best-practicesSkill
- vertical-fanned-cardsSkill
- video-contentSkill
- war-roomSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
No token storage in frontend
- Distinctive: line 134
Create project in Google Cloud Console
- Distinctive: line 136
Create OAuth 2.0 credentials (Web application)
- Distinctive: line 137
Run auth script locally to get tokens:
- Distinctive: line 165
Never expose tokens in frontend: - always go through proxy
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Gmail Proxy Skill
Build Gmail/Calendar integration via a REST proxy instead of implementing OAuth in your frontend.
When to Use
- You need Gmail/Calendar access in a web app
- You want to avoid OAuth complexity in the frontend
- You need to support multiple Google accounts
- You want a clean API abstraction layer
Architecture
Frontend (Vercel) → REST Proxy (Railway) → Gmail/Calendar APIWhy this pattern?
- Proxy handles OAuth, token refresh, multiple accounts
- Frontend just makes simple REST calls with API key
- One source of truth for Google API access
- No token storage in frontend
Implementation
1. Create the Proxy (Node.js/Express)
const express = require('express');
const app = express();
app.use(express.json({ limit: '25mb' }));
// CORS for browser access
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, X-Api-Key');
if (req.method === 'OPTIONS') return res.sendStatus(200);
next();
});
// API key auth
const API_KEY = process.env.API_KEY;
function auth(req, res, next) {
const key = req.query.key || req.headers['x-api-key'];
if (key !== API_KEY) return res.status(401).json({ error: 'Unauthorized' });
next();
}
// Token management - load from env vars
const tokens = {};
for (const key of Object.keys(process.env)) {
if (key.startsWith('TOKENS_')) {
const account = key.replace('TOKENS_', '').toLowerCase();
tokens[account] = JSON.parse(process.env[key]);
}
}2. Key Endpoints
// List emails
app.get('/gmail/messages', auth, async (req, res) => {
const { account, max = 10, q = '' } = req.query;
// Call Gmail API with tokens[account]
});
// Send email (with optional 'from' for aliases)
app.post('/gmail/send', auth, async (req, res) => {
const { account, to, subject, body, from } = req.body;
const fromAddress = from || tokens[account].email;
// Build MIME message and send
});
// Create draft
app.post('/gmail/drafts', auth, async (req, res) => {
const { account, to, subject, body, threadId, replyToMessageId } = req.body;
// Create draft, optionally as reply
});
// Calendar events
app.get('/calendar/events', auth, async (req, res) => {
const { account, days = 7 } = req.query;
// Fetch events for next N days
});3. Deploy to Railway
# railway.toml
[build]
builder = "nixpacks"
[deploy]
startCommand = "node index.js"Environment variables needed:
API_KEY- Your API key for authGOOGLE_CLIENT_ID- OAuth client IDGOOGLE_CLIENT_SECRET- OAuth client secretTOKENS_PERSONAL- JSON tokens for personal accountTOKENS_WORK- JSON tokens for work account
4. Frontend Usage
const PROXY_URL = 'https://your-proxy.railway.app';
const API_KEY = process.env.NEXT_PUBLIC_PROXY_KEY;
// Fetch emails
const res = await fetch(
`${PROXY_URL}/gmail/messages?account=personal&max=10&key=${API_KEY}`
);
const { messages } = await res.json();
// Send email
await fetch(`${PROXY_URL}/gmail/send?key=${API_KEY}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
account: 'work',
to: 'someone@example.com',
subject: 'Hello',
body: 'Email body here'
})
});OAuth Setup (One-time)
- Create project in Google Cloud Console
- Enable Gmail API and Calendar API
- Create OAuth 2.0 credentials (Web application)
- Run auth script locally to get tokens:
// auth.js - run once per account
const { google } = require('googleapis');
const readline = require('readline');
const oauth2Client = new google.auth.OAuth2(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
'http://localhost:3000/callback'
);
const authUrl = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: [
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.compose',
'https://www.googleapis.com/auth/calendar'
]
});
console.log('Visit:', authUrl);
// Exchange code for tokens, save to env varBest Practices
- Never expose tokens in frontend - always go through proxy
- Use API key auth - simple but effective for private APIs
- Enable CORS - required for browser access
- Handle token refresh - Google tokens expire, proxy should auto-refresh
- Support multiple accounts - load tokens by account name
- Add 'from' parameter - for sending as aliases
Files
examples/proxy-server.js- Full proxy implementationexamples/frontend-usage.ts- TypeScript frontend examplestemplates/railway.toml- Railway config
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

