Add Gmail Send Tool (send_email_gmail) with OAuth Authentication

Resolved 💬 2 comments Opened Jan 15, 2026 by ahmedyounis Closed Feb 13, 2026

Problem

Currently, emails sent via AWS SES (send_email tool) are not saved anywhere accessible. There's no way to retrieve what was sent later, and it requires separate AWS credentials.

Solution

Add a new send_email_gmail tool that sends emails via Gmail API using existing OAuth authentication (same tokens used for reading emails).

Benefits

  • Sent emails appear in Gmail Sent folder automatically
  • Can be retrieved later using existing Gmail tools (list_emails, get_email)
  • Uses existing OAuth tokens (no additional credentials needed)
  • Returns message_id and thread_id for conversation tracking

Implementation

Add new tool to merakey-mcp-server/src/tools/gmail.ts:

  • Reuse buildRawEmail() from email-builder.ts for MIME email construction
  • Use existing getGmailClient() for OAuth authentication
  • Call gmail.users.messages.send() with base64-encoded email
  • Support both merakey and healex accounts
  • Auto-log activity to CRM if log_to_client_id or log_to_lead_id provided

Technical Details

  • Gmail API method: gmail.users.messages.send({ userId: 'me', requestBody: { raw: base64Email } })
  • Encoding: Base64URL encoding required
  • Scope: Already granted (gmail.modify)
  • Rate limits: 1000 messages/day (free tier), 10,000/day (Google Workspace)

Use Cases

Gmail send (send_email_gmail):

  • Personal correspondence
  • Client emails you need to reference later
  • Emails that should appear in Sent folder

AWS SES (send_email):

  • Bulk/transactional emails (invoices, notifications)
  • Emails from verified sender identities (billing@merakey.io)

Files to Modify

  • merakey-mcp-server/src/tools/gmail.ts - Add send_email_gmail tool
  • Import from merakey-mcp-server/src/tools/utils/email-builder.ts (no changes needed)

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗