tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK with Gmail - Reading and Sending Email

ADK with Gmail - Reading and Sending Email

Author: Venkata Sudhakar

Integrating Gmail with ADK agents allows automated email workflows - reading customer enquiries, sending order confirmations, and forwarding alerts without any manual intervention. ShopMax India uses a Gmail-connected agent to monitor the support inbox and reply to common queries about order status and delivery timelines.

The Gmail API uses OAuth 2.0 scopes. For server-side ADK agents running on Cloud Run, a service account with domain-wide delegation is the recommended approach - no user interaction required. The agent gets a delegated credential for the shared support inbox and can read, label, and send messages programmatically.

The below example shows an ADK agent with two Gmail tools: one to read recent unread messages and one to send a reply.


It gives the following output,

Found 2 unread emails:
  1. From: [email protected]  - Subject: "Where is my order ORD-1042?"
  2. From: [email protected]  - Subject: "Return request for ORD-0988"

Replied to [email protected]:
  "Dear Ravi, your order ORD-1042 is out for delivery and expected by 6 PM today.
   Regards, ShopMax Support Team"

Replied to [email protected]:
  "Dear Priya, your return request has been logged. Our team will collect the item within 2 business days.
   Regards, ShopMax Support Team"

For production, store the service account JSON in Secret Manager rather than a mounted file, add the gmail.modify scope to mark emails as read after processing, and use Pub/Sub Gmail push notifications instead of polling so the agent triggers in real time when new mail arrives. Store processed message IDs in Firestore to prevent duplicate replies.


 
  


  
bl  br