SKILL.md
readonlyread-only
name
gmail-workflows
description
透過智慧工作流程自動化 Gmail - 附件管理、郵件分類、自動封存及 Google Drive 整合
version
1.0.0
Gmail 工作流程
透過智慧工作流程自動化 Gmail,實現附件管理、郵件分類及 Google Drive 整合。基於 n8n 的 7,800 多個工作流程範本。
概述
此技能協助您設計並實作 Gmail 自動化工作流程,可:
- 自動將附件儲存至 Google Drive
- 使用智慧標籤分類郵件
- 封存已處理的郵件
- 透過 Slack/Email 發送通知
- 追蹤郵件指標
核心工作流程範本
1. Gmail 附件管理員
目的:自動從郵件中擷取附件並儲存至 Google Drive
工作流程步驟:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Gmail │───▶│ 依條件篩選 │───▶│ 擷取附件 │───▶│ 上傳至 │
│ 觸發器 │ │ │ │ │ │ Google Drive│
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
│
┌─────────────┐ ┌─────────────┐ │
│ 發送通知 │◀───│ 套用標籤 │◀───┘
│ │ │ 與封存 │
└─────────────┘ └─────────────┘
設定:
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: "新附件已儲存:{filename} 來自 {sender}"
最佳實務:
- 使用特定寄件者篩選條件以避免處理垃圾郵件
- 設定檔案大小限制以防止儲存空間問題
- 使用以日期為基礎的資料夾結構以便於檢索
- 啟用重複偵測以避免重複上傳
2. 發票自動封存器
目的:自動從郵件中收集並整理發票
工作流程步驟:
Gmail 觸發器 → 偵測發票 → 擷取 PDF → OCR/解析 → 儲存至 Drive → 更新試算表 → 封存郵件
設定:
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: "客戶 A 郵件"
condition:
from_domain: "clienta.com"
actions:
- apply_label: "Clients/Client A"
- forward_to: "team-a@company.com"
- save_attachments: "/Clients/Client A/{subject}"
- name: "專案 X 更新"
condition:
subject_contains: ["Project X", "PX-"]
actions:
- apply_label: "Projects/Project X"
- add_to_task: "Project X Board"
- notify_slack: "#project-x"
- name: "緊急請求"
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 工作流程:Gmail 到 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 到 Drive 自動化
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 => {
// 儲存至 Drive
const file = targetFolder.createFile(attachment);
// 以日期和寄件者重新命名
const newName = `${Utilities.formatDate(message.getDate(), 'GMT', 'yyyy-MM-dd')}_${message.getFrom()}_${attachment.getName()}`;
file.setName(newName);
});
// 標記為已處理
message.markRead();
thread.addLabel(GmailApp.getUserLabelByName('Processed'));
});
});
}
// 設定觸發器
function setupTrigger() {
ScriptApp.newTrigger('processNewEmails')
.timeBased()
.everyMinutes(5)
.create();
}
常見工作流程模式
模式 1:篩選 → 處理 → 整理 → 通知
郵件送達
│
▼
┌─────────────────┐
│ 套用篩選條件 │ → 若不符合則跳過
│ (寄件者、主旨 │
│ 附件) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ 處理內容 │ → 擷取資料、附件
│ │
└────────┬────────┘
│
▼
┌─────────────────┐
│ 整理 │ → 儲存檔案、套用標籤
│ │
└────────┬────────┘
│
▼
┌─────────────────┐
│ 通知 │ → Slack、Email、SMS
│ │
└─────────────────┘
模式 2:批次處理
schedule: "daily at 6am"
steps:
1. 收集過去 24 小時內所有未處理郵件
2. 依類別分組(發票、報表、其他)
3. 批次上傳至對應的 Drive 資料夾
4. 產生摘要報表
5. 發送每日摘要給利害關係人
模式 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.file用於 Drive 存取
-
資料隱私:
- 不要記錄郵件內容
- 使用安全儲存存放憑證
- 實施保留政策
-
存取控制:
- 限制可修改工作流程的人員
- 稽核自動化活動
- 使用獨立服務帳戶
輸出範例
每日郵件報表:
# 郵件活動報表 - 2026-01-30
## 摘要
- 收到的郵件:47
- 寄出的郵件:23
- 處理的附件:12
- 平均回覆時間:2.3 小時
## 附件處理
| 檔案 | 寄件者 | 儲存位置 | 時間 |
|------|--------|----------|------|
| Invoice_Jan.pdf | vendor@co.com | /Finance/Invoices | 09:15 |
| Report_Q4.xlsx | team@company.com | /Reports/Q4 | 10:30 |
| Contract_v2.docx | legal@client.com | /Contracts | 14:22 |
## 已套用標籤
- Finance/Invoices:5 封郵件
- Projects/Active:12 封郵件
- Clients/Priority:8 封郵件
## 待辦事項
- 3 封郵件需要人工審閱
- 2 個大型附件需要核准
Gmail 工作流程技能 - Claude Office Skills 的一部分






