关于 gmail-workflows
gmail-workflows 是用于设计和实现 Gmail 自动化工作流的技能,面向希望整理邮件、附件及相关记录的人。它提供基于 n8n 工作流模板的模式,也介绍 Google Apps Script 实现方式。
主要功能
- 01筛选邮件并保存附件到 Google Drive
- 02按条件应用标签和归档邮件
- 03整理客户邮件并转发通知
- 04收集发票并更新表格
- 05跟踪邮件指标并生成报告
适用场景
- 01自动归档邮件中的发票附件
- 02按客户或项目整理来信
- 03将新附件分类保存到 Drive
- 04汇总邮件数量和响应时间
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ claude-office-skills/ skills --skill gmail-workflows安装后在 Claude Code 中输入/gmail-workflows确认已加载。
详细介绍
Gmail 工作流
使用智能工作流自动处理 Gmail,包括附件管理、邮件整理和 Google Drive 集成。基于 n8n 的 7,800 多个工作流模板。
概述
此技能可帮助你设计和实现 Gmail 自动化工作流,以便:
- 自动将附件保存到 Google Drive
- 使用智能标签整理邮件
- 归档已处理的邮件
- 通过 Slack/Email 发送通知
- 跟踪邮件指标
核心工作流模板
1. Gmail 附件管理器
用途:自动提取邮件附件并保存到 Google Drive
工作流步骤:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Gmail │───▶│ Filter by │───▶│ Extract │───▶│ Upload to │
│ Trigger │ │ Criteria │ │ Attachments │ │ Google Drive│
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
│
┌─────────────┐ ┌─────────────┐ │
│ Send │◀───│ Apply Label │◀───┘
│ Notification│ │ & Archive │
└─────────────┘ └─────────────┘
配置:
trigger:
type: gmail_new_email
filters:
has_attachment: true
from: ["*@company.com", "*@vendor.com"]
subject_contains: ["invoice", "report", "contract"]
actions:
- extract_attachments:
file_types: [pdf, xlsx, docx, csv]
max_size_mb: 25
- upload_to_drive:
folder_path: "/Attachments/{year}/{month}"
naming_pattern: "{filename}_{sender}_{date}"
create_folder_if_missing: true
- organize_email:
apply_label: "Processed/Attachments"
mark_as_read: true
archive: true
- notify:
channel: slack
message: "New attachment saved: {filename} from {sender}"
最佳实践:
- 使用具体的发件人筛选条件,避免处理垃圾邮件
- 设置文件大小限制,防止存储问题
- 使用基于日期的文件夹结构,以便轻松检索
- 启用重复检测,避免重复上传
2. 发票自动归档器
用途:自动收集和整理邮件中的发票
工作流步骤:
Gmail Trigger → Detect Invoice → Extract PDF → OCR/Parse → Save to Drive → Update Spreadsheet → Archive Email
配置:
trigger:
subject_patterns:
- "invoice"
- "bill"
- "statement"
- "付款"
- "发票"
processing:
- detect_invoice:
methods: [subject_keywords, attachment_name, sender_domain]
- extract_data:
fields: [invoice_number, amount, date, vendor, due_date]
use_ocr: true
- save_to_drive:
folder: "/Finance/Invoices/{year}/{vendor}"
naming: "{date}_{vendor}_{amount}"
- update_tracker:
spreadsheet: "Invoice Tracker"
columns: [Date, Vendor, Amount, Invoice#, Status, File_Link]
- archive:
label: "Finance/Invoices"
star: true
3. 客户沟通整理器
用途:按项目/客户自动整理客户邮件
配置:
rules:
- name: "Client A Emails"
condition:
from_domain: "clienta.com"
actions:
- apply_label: "Clients/Client A"
- forward_to: "[email protected]"
- save_attachments: "/Clients/Client A/{subject}"
- name: "Project X Updates"
condition:
subject_contains: ["Project X", "PX-"]
actions:
- apply_label: "Projects/Project X"
- add_to_task: "Project X Board"
- notify_slack: "#project-x"
- name: "Urgent Requests"
condition:
subject_contains: ["URGENT", "ASAP", "紧急"]
is_unread: true
actions:
- apply_label: "Priority/Urgent"
- send_sms: "+1234567890"
- move_to_inbox: true
4. 邮件分析仪表板
用途:跟踪邮件指标并生成报告
要跟踪的指标:
daily_metrics:
- emails_received: count(inbox)
- emails_sent: count(sent)
- response_time_avg: avg(reply_time)
- unread_count: count(unread)
- attachment_count: count(has_attachment)
weekly_report:
- top_senders: group_by(from, count)
- busiest_hours: group_by(hour, count)
- label_distribution: group_by(label, count)
- response_rate: sent / received
automation:
- schedule: "every Monday 9am"
- output: Google Sheets
- notify: Slack #email-metrics
实施指南
使用 n8n
// n8n Workflow: Gmail to Google Drive
{
"nodes": [
{
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"parameters": {
"pollTimes": { "item": [{ "mode": "everyMinute" }] },
"filters": { "labelIds": ["INBOX"] }
}
},
{
"name": "Filter Attachments",
"type": "n8n-nodes-base.if",
"parameters": {
"conditions": {
"boolean": [{
"value1": "={{ $json.hasAttachment }}",
"value2": true
}]
}
}
},
{
"name": "Get Attachments",
"type": "n8n-nodes-base.gmail",
"parameters": {
"operation": "getAttachments",
"messageId": "={{ $json.id }}"
}
},
{
"name": "Upload to Drive",
"type": "n8n-nodes-base.googleDrive",
"parameters": {
"operation": "upload",
"folderId": "your-folder-id",
"name": "={{ $json.filename }}"
}
}
]
}
使用 Google Apps Script
// Gmail to Drive Automation
function processNewEmails() {
const threads = GmailApp.search('has:attachment is:unread');
const targetFolder = DriveApp.getFolderById('FOLDER_ID');
threads.forEach(thread => {
const messages = thread.getMessages();
messages.forEach(message => {
const attachments = message.getAttachments();
attachments.forEach(attachment => {
// Save to Drive
const file = targetFolder.createFile(attachment);
// Rename with date and sender
const newName = `${Utilities.formatDate(message.getDate(), 'GMT', 'yyyy-MM-dd')}_${message.getFrom()}_${attachment.getName()}`;
file.setName(newName);
});
// Mark as processed
message.markRead();
thread.addLabel(GmailApp.getUserLabelByName('Processed'));
});
});
}
// Set up trigger
function setupTrigger() {
ScriptApp.newTrigger('processNewEmails')
.timeBased()
.everyMinutes(5)
.create();
}
常见工作流模式
模式 1:筛选 → 处理 → 整理 → 通知
Email arrives
│
▼
┌─────────────────┐
│ Apply Filters │ → Skip if doesn't match
│ (sender, subject│
│ attachment) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Process Content │ → Extract data, attachments
│ │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Organize │ → Save files, apply labels
│ │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Notify │ → Slack, email, SMS
│ │
└─────────────────┘
模式 2:批量处理
schedule: "daily at 6am"
steps:
1. Collect all unprocessed emails from last 24h
2. Group by category (invoices, reports, misc)
3. Batch upload to respective Drive folders
4. Generate summary report
5. Send daily digest to stakeholders
模式 3:条件路由
conditions:
- if: attachment_type == "pdf" AND subject contains "invoice"
then: route_to_finance_folder
- if: from_domain in ["important-client.com"]
then: priority_handling + immediate_notification
- if: attachment_size > 10MB
then: save_to_large_files_folder + skip_backup
- default:
then: standard_processing
故障排除
常见问题
| 问题 | 解决方案 |
|---|---|
| 未检测到附件 | 检查 MIME 类型筛选条件,提高触发频率 |
| 文件重复 | 按哈希值或文件名启用去重 |
| 速率限制 | 降低触发频率,使用批量处理 |
| 权限错误 | 重新授权 OAuth 凭据 |
| 大文件处理失败 | 设置大小限制,使用分块上传 |
安全注意事项
-
OAuth 权限范围:仅申请最低限度的权限
- 读取邮件使用
gmail.readonly - 管理标签/归档使用
gmail.modify - 访问 Drive 使用
drive.file
- 读取邮件使用
-
数据隐私:
- 不要记录邮件内容
- 使用安全的凭据存储方式
- 制定数据保留策略
-
访问控制:
- 限制可修改工作流的人员
- 审核自动化活动
- 使用单独的服务账号
输出示例
每日邮件报告:
# Email Activity Report - 2026-01-30
## Summary
- Emails Received: 47
- Emails Sent: 23
- Attachments Processed: 12
- Average Response Time: 2.3 hours
## Attachment Processing
| File | Sender | Saved To | Time |
|------|--------|----------|------|
| Invoice_Jan.pdf | [email protected] | /Finance/Invoices | 09:15 |
| Report_Q4.xlsx | [email protected] | /Reports/Q4 | 10:30 |
| Contract_v2.docx | [email protected] | /Contracts | 14:22 |
## Labels Applied
- Finance/Invoices: 5 emails
- Projects/Active: 12 emails
- Clients/Priority: 8 emails
## Pending Actions
- 3 emails require manual review
- 2 large attachments need approval
Gmail 工作流技能 - 属于 Claude Office Skills
评论
支持 Markdown