ConnectOnionConnectOnion
DocsUseful Pluginsgmail_plugin

gmail_plugin

Email approval and CRM sync for Gmail operations

What it does

The gmail_plugin provides two features for Gmail-powered agents:

Email Approval (before_each_tool)

Shows a preview and asks for confirmation before sending any email.

CRM Sync (after_each_tool)

After sending, updates contact's last_contact date in the CRM.

Quick Start

main.py
1from connectonion import Agent, Gmail 2from connectonion.useful_plugins import gmail_plugin 3 4gmail = Gmail() # Requires OAuth setup: co auth google 5 6agent = Agent("email_assistant", tools=[gmail], plugins=[gmail_plugin]) 7 8agent.input("Send an email to john@example.com about the meeting tomorrow")
Python REPL
Interactive
┌─ Email to Send ────────────────────────┐
│ To: john@example.com │
│ Subject: Meeting Tomorrow │
│ │
│ Hi John, │
│ │
│ This is a reminder about our meeting │
│ scheduled for tomorrow... │
└────────────────────────────────────────┘
Send this email?
> Yes, send it
> Auto approve emails to 'john@example.com'
> Auto approve all emails this session
 
[Sending...]
CRM updated: john@example.com

Approval Options

For New Emails

Yes, send it

Send this specific email

Auto approve emails to '{recipient}'

Auto-approve all emails to this recipient for this session

Auto approve all emails this session

Skip approval for all emails (use with caution)

For Replies

When replying to threads, you get similar options plus "Auto approve all replies this session".

CRM Integration

After each successful email send, the plugin automatically updates the contact's CRM data:

main.py
1@after_each_tool 2def sync_crm_after_send(agent): 3 trace = agent.current_session['trace'][-1] 4 5 # Only after successful email sends 6 if trace['tool_name'] not in ('send', 'reply'): 7 return 8 if trace['status'] != 'success': 9 return 10 11 to = trace['arguments'].get('to', '') 12 if not to: 13 return 14 15 # Access Gmail instance via agent.tools.gmail 16 gmail = agent.tools.gmail 17 today = datetime.now().strftime('%Y-%m-%d') 18 19 # Update last_contact date, clear next_contact_date 20 gmail.update_contact(to, last_contact=today, next_contact_date='')

Events Used

EventHandlerPurpose
before_each_toolcheck_email_approvalPreview and approve emails
after_each_toolsync_crm_after_sendUpdate CRM after send

Related

Source

connectonion/useful_plugins/gmail_plugin.py

main.py
1# Bundle both handlers as plugin 2gmail_plugin = [ 3 check_email_approval, 4 sync_crm_after_send, 5]