Gmail Inbox integration
Fully automate CAS retrieval with no manual refreshes. No security audit required
Architecture: Email Import
This guide covers importing CAS statements directly from user email inboxes via OAuth.
Overview
Connect to user email via OAuth, search for CAS statements, and parse them automatically.
Supported providers: Gmail (more coming soon)
Detected senders:
-
CDSL (
cdsl) -
NSDL (
nsdl) -
CAMS (
cams) -
KFintech (
kfintech)
User Flow
┌─────────────────────────────────────────────────────────────────────────────┐
│ │
│ User Journey │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────┐ │
│ │ │ │ │ │ │ │ │ │
│ │ Clicks │────►│ Grants │────►│ Enters │────►│ Views │ │
│ │ "Connect │ │ Gmail │ │ password │ │ data │ │
│ │ Inbox" │ │ access │ │ │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
Data Flow
Phase 1: Connect
┌──────────┐ ┌──────────┐ ┌─────────────┐ ┌──────────┐
│ User │ │ Your App │ │ CAS Parser │ │ Google │
└────┬─────┘ └────┬─────┘ └──────┬──────┘ └────┬─────┘
│ │ │ │
│ Click "Connect │ │ │
│ Email" │ │ │
│───────────────►│ │ │
│ │ │ │
│ │ Get OAuth URL │ │
│ │─────────────────►│ │
│ │ │ │
│ │ oauth_url │ │
│ │◄─────────────────│ │
│ │ │ │
│ Redirect to Google consent │ │
│◄──────────────────────────────────────────────────►│
│ │ │ │
│ Grant access │ │ │
│───────────────────────────────────────────────────►│
│ │ │ │
│ Redirect back with inbox_token │ │
│◄───────────────│ │ │
│ │ │ │
Phase 2: Fetch & Parse
┌──────────┐ ┌──────────┐ ┌─────────────┐ ┌──────────┐
│ User │ │ Your App │ │ CAS Parser │ │ Gmail │
└────┬─────┘ └────┬─────┘ └──────┬──────┘ └────┬─────┘
│ │ │ │
│ Sync portfolio │ │ │
│───────────────►│ │ │
│ │ │ │
│ │ List CAS files │ │
│ │ (inbox_token) │ │
│ │─────────────────►│ │
│ │ │ │
│ │ │ Search inbox │
│ │ │────────────────►│
│ │ │ │
│ │ │ CAS emails │
│ │ │◄────────────────│
│ │ │ │
│ │ File URLs │ │
│ │◄─────────────────│ │
│ │ │ │
│ Enter password │ │ │
│───────────────►│ │ │
│ │ │ │
│ │ Parse files │ │
│ │─────────────────►│ │
│ │ │ │
│ │ Portfolio data │ │
│ │◄─────────────────│ │
│ │ │ │
│ View portfolio │ │ │
│◄───────────────│ │ │
│ │ │ │
Integration Patterns
Pattern A: On-Demand Sync
User triggers sync manually.
User clicks "Sync"
│
▼
Check connection valid?
│
No ──┴── Yes
│ │
▼ ▼
OAuth List CAS files
│
▼
Filter new files (by message_id)
│
▼
Prompt for password
│
▼
Parse & store
Pattern B: Background Sync
Periodic sync with stored credentials.
Scheduled job (weekly or monthly)
│
▼
For each connected user:
│
▼
List CAS files (last 30 days)
│
▼
Filter already-processed message_ids
│
▼
Parse with stored password
│
▼
Update portfolio
Pattern C: Generator + Inbox
Request new CAS, then auto-import when it arrives.
Request CAS via KFintech
│
▼
Poll inbox every 30s
│
▼
New CAS detected
│
▼
Parse automatically
This pattern eliminates user upload entirely.
Security
|
Aspect |
Details |
|---|---|
|
Permission scope |
Read-only ( |
|
Token storage |
Encrypted with server-side secret |
|
File URLs |
Presigned, expire in 24 hours |
|
Revocation |
User can disconnect anytime |
API Documentation
Full endpoint documentation and request/response schemas:
Related Guides
-
CAS Parsing — Parse when user has the PDF
-
CAS Generator — Request CAS when user doesn't have the PDF