Skip to content
All Skills

Gmail Email Drafter

Draft and send emails via Gmail using Google CLI. Analyzes your sent mail for tone matching, composes context-aware drafts, and creates Gmail drafts ready to send. Prerequisites: gcloud, curl, jq, base64.

Email & Communication|v1|Updated 5/18/2026
MCP get_skill({ skillId: "gmail-email-drafter-cc1046f1" })

Use this skill with your agent

Create a free account and connect via MCP

Get Started Free
# Gmail Email Drafter

Draft professional emails that match your writing style using Gmail API via Google CLI. Creates drafts in your Gmail account ready for review and sending.

## When to Use

- "Draft an email to [person] about [topic]"
- "Write a reply to [person]'s last email"
- "Compose a follow-up email about [project]"

## Requirements

- **Google Cloud CLI** (`gcloud`) installed and authenticated
- Gmail API enabled in Google Cloud project
- OAuth2 credentials with `gmail.compose`, `gmail.readonly` scopes
- `jq` for JSON parsing

## Workflow

### Step 1 — Authenticate & Verify Access

```bash
# Verify gcloud is authenticated
gcloud auth list

# Get access token for Gmail API
ACCESS_TOKEN=$(gcloud auth print-access-token)

# Verify Gmail access
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "https://gmail.googleapis.com/gmail/v1/users/me/profile" | jq '.emailAddress'
```

If authentication fails, run:
```bash
gcloud auth login --scopes=https://www.googleapis.com/auth/gmail.compose,https://www.googleapis.com/auth/gmail.readonly
```

### Step 2 — Analyze Tone from Sent Mail

Pull the user's recent sent emails to learn their writing style:

```bash
# Fetch last 5 sent emails
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "https://gmail.googleapis.com/gmail/v1/users/me/messages?q=in:sent&maxResults=5" | jq '.messages[].id'

# For each message ID, fetch the full content
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "https://gmail.googleapis.com/gmail/v1/users/me/messages/{MESSAGE_ID}?format=full" | \
  jq '{subject: (.payload.headers[] | select(.name=="Subject") | .value), to: (.payload.headers[] | select(.name=="To") | .value)}'
```

Analyze patterns:
- **Greeting style** — "Hi", "Hello", "Dear", or direct (no greeting)
- **Structure** — short paragraphs vs. bullet lists
- **Sign-off** — "Best", "Thanks", "Regards", full name vs. first name
- **Formality level** — professional, friendly-professional, casual

### Step 3 — If Replying, Fetch the Original Thread

```bash
# Search for emails from the recipient
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "https://gmail.googleapis.com/gmail/v1/users/me/messages?q=from:{RECIPIENT_EMAIL}&maxResults=3" | jq '.messages[].id'

# Get thread context
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "https://gmail.googleapis.com/gmail/v1/users/me/threads/{THREAD_ID}?format=full" | jq '.messages[-1]'
```

### Step 4 — Compose the Draft

1. Apply the user's discovered tone and style
2. Structure: context → main point → call to action
3. Keep under 200 words unless the user requests more detail
4. Present the draft to the user for review in markdown format

### Step 5 — Create Gmail Draft

After user approves the draft:

```bash
# Base64url encode the email
EMAIL_CONTENT=$(cat <<'EOF'
From: me
To: {RECIPIENT}
Subject: {SUBJECT}
Content-Type: text/plain; charset=utf-8

{BODY}
EOF
)

ENCODED=$(echo -n "$EMAIL_CONTENT" | base64 -w 0 | tr '+/' '-_' | tr -d '=')

# Create draft in Gmail
curl -s -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"message\": {\"raw\": \"$ENCODED\"}}" \
  "https://gmail.googleapis.com/gmail/v1/users/me/drafts"
```

### Step 6 — Confirm

Report back: "Draft created in Gmail. Open Gmail to review and send."
Provide the draft ID for reference.

## Important Rules

- **Never send emails directly** — only create drafts for user review
- Always show the full email to the user before creating the draft
- If tone analysis fails, fall back to professional defaults
- Never include sensitive data from unrelated email threads

## Example Prompts

- "Draft an email to sarah@acme.com about the project deadline"
- "Write a follow-up to my last conversation with John about the contract"
- "Compose a cold intro email to the VP of Engineering at TechCorp"
#gmail#email#google-cli#communicationgcloudcurljqbase64