gmail-workflows

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Gmail Workflows

Gmail 工作流

Automate Gmail with intelligent workflows for attachment management, email organization, and Google Drive integration. Based on n8n's 7,800+ workflow templates.
借助智能工作流实现Gmail自动化,涵盖附件管理、邮件整理及Google Drive集成。基于n8n的7800+工作流模板。

Overview

概述

This skill helps you design and implement Gmail automation workflows that:
  • Automatically save attachments to Google Drive
  • Organize emails with smart labeling
  • Archive processed emails
  • Send notifications via Slack/Email
  • Track email metrics
本技能可帮助你设计并实现Gmail自动化工作流,包括:
  • 自动将附件保存至Google Drive
  • 借助智能标签整理邮件
  • 归档已处理邮件
  • 通过Slack/邮件发送通知
  • 追踪邮件指标

Core Workflow Templates

核心工作流模板

1. Gmail Attachment Manager

1. Gmail 附件管理器

Purpose: Automatically extract attachments from emails and save to Google Drive
Workflow Steps:
┌─────────────┐    ┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│ Gmail       │───▶│ Filter by   │───▶│ Extract     │───▶│ Upload to   │
│ Trigger     │    │ Criteria    │    │ Attachments │    │ Google Drive│
└─────────────┘    └─────────────┘    └─────────────┘    └─────────────┘
                         ┌─────────────┐    ┌─────────────┐    │
                         │ Send        │◀───│ Apply Label │◀───┘
                         │ Notification│    │ & Archive   │
                         └─────────────┘    └─────────────┘
Configuration:
yaml
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}"
Best Practices:
  • Use specific sender filters to avoid processing spam
  • Set file size limits to prevent storage issues
  • Use date-based folder structure for easy retrieval
  • Enable duplicate detection to avoid redundant uploads

用途:自动提取邮件中的附件并保存至Google Drive
工作流步骤:
┌─────────────┐    ┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│ Gmail       │───▶│ Filter by   │───▶│ Extract     │───▶│ Upload to   │
│ Trigger     │    │ Criteria    │    │ Attachments │    │ Google Drive│
└─────────────┘    └─────────────┘    └─────────────┘    └─────────────┘
                         ┌─────────────┐    ┌─────────────┐    │
                         │ Send        │◀───│ Apply Label │◀───┘
                         │ Notification│    │ & Archive   │
                         └─────────────┘    └─────────────┘
配置:
yaml
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. Invoice Auto-Archiver

2. 发票自动归档器

Purpose: Automatically collect and organize invoices from email
Workflow Steps:
Gmail Trigger → Detect Invoice → Extract PDF → OCR/Parse → Save to Drive → Update Spreadsheet → Archive Email
Configuration:
yaml
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

用途:自动收集并整理邮件中的发票
工作流步骤:
Gmail Trigger → Detect Invoice → Extract PDF → OCR/Parse → Save to Drive → Update Spreadsheet → Archive Email
配置:
yaml
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. Client Communication Organizer

3. 客户沟通整理器

Purpose: Automatically organize client emails by project/client
Configuration:
yaml
rules:
  - name: "Client A Emails"
    condition:
      from_domain: "clienta.com"
    actions:
      - apply_label: "Clients/Client A"
      - forward_to: "team-a@company.com"
      - 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

用途:按项目/客户自动整理客户邮件
配置:
yaml
rules:
  - name: "Client A Emails"
    condition:
      from_domain: "clienta.com"
    actions:
      - apply_label: "Clients/Client A"
      - forward_to: "team-a@company.com"
      - 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. Email Analytics Dashboard

4. 邮件分析仪表盘

Purpose: Track email metrics and generate reports
Metrics to Track:
yaml
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

用途:追踪邮件指标并生成报告
追踪指标:
yaml
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

Implementation Guide

实施指南

Using n8n

使用n8n

javascript
// 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 }}"
      }
    }
  ]
}
javascript
// 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 }}"
      }
    }
  ]
}

Using Google Apps Script

使用Google Apps Script

javascript
// 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();
}

javascript
// 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();
}

Common Workflow Patterns

常见工作流模式

Pattern 1: Filter → Process → Organize → Notify

模式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
│                 │
└─────────────────┘
邮件到达
┌─────────────────┐
│ 应用过滤器      │ → 不匹配则跳过
│(发件人、主题、│
│ 附件)          │
└────────┬────────┘
┌─────────────────┐
│ 处理内容        │ → 提取数据、附件
│                 │
└────────┬────────┘
┌─────────────────┐
│ 整理归类        │ → 保存文件、添加标签
│                 │
└────────┬────────┘
┌─────────────────┐
│ 发送通知        │ → Slack、邮件、短信
│                 │
└─────────────────┘

Pattern 2: Batch Processing

模式2:批量处理

yaml
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
yaml
schedule: "daily at 6am"
steps:
  1. 收集过去24小时内所有未处理的邮件
  2. 按类别分组(发票、报告、其他)
  3. 批量上传至对应Drive文件夹
  4. 生成汇总报告
  5. 向相关人员发送每日摘要

Pattern 3: Conditional Routing

模式3:条件路由

yaml
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

yaml
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

Troubleshooting

故障排除

Common Issues

常见问题

IssueSolution
Attachments not detectedCheck MIME type filters, increase trigger frequency
Duplicate filesEnable deduplication by hash or filename
Rate limitsReduce trigger frequency, use batch processing
Permission errorsRe-authorize OAuth credentials
Large files failingSet size limits, use chunked upload

问题解决方案
附件未被检测到检查MIME类型过滤器,提高触发频率
重复文件启用基于哈希或文件名的去重机制
速率限制降低触发频率,使用批量处理
权限错误重新授权OAuth凭证
大文件上传失败设置大小限制,使用分块上传

Security Considerations

安全注意事项

  1. OAuth Scopes: Request minimal permissions
    • gmail.readonly
      for reading
    • gmail.modify
      for labels/archive
    • drive.file
      for Drive access
  2. Data Privacy:
    • Don't log email content
    • Use secure storage for credentials
    • Implement retention policies
  3. Access Control:
    • Limit who can modify workflows
    • Audit automation activities
    • Use separate service accounts

  1. OAuth 权限范围:请求最小权限
    • gmail.readonly
      用于读取邮件
    • gmail.modify
      用于添加标签/归档
    • drive.file
      用于Drive访问
  2. 数据隐私:
    • 不要记录邮件内容
    • 使用安全方式存储凭证
    • 实施数据保留策略
  3. 访问控制:
    • 限制可修改工作流的人员
    • 审计自动化活动
    • 使用独立服务账号

Output Example

输出示例

Daily Email Report:
markdown
undefined
每日邮件报告:
markdown
undefined

Email Activity Report - 2026-01-30

邮件活动报告 - 2026-01-30

Summary

摘要

  • Emails Received: 47
  • Emails Sent: 23
  • Attachments Processed: 12
  • Average Response Time: 2.3 hours
  • 收到邮件:47封
  • 发送邮件:23封
  • 已处理附件:12个
  • 平均响应时间:2.3小时

Attachment Processing

附件处理情况

FileSenderSaved ToTime
Invoice_Jan.pdfvendor@co.com/Finance/Invoices09:15
Report_Q4.xlsxteam@company.com/Reports/Q410:30
Contract_v2.docxlegal@client.com/Contracts14:22
文件发件人保存路径时间
Invoice_Jan.pdfvendor@co.com/Finance/Invoices09:15
Report_Q4.xlsxteam@company.com/Reports/Q410:30
Contract_v2.docxlegal@client.com/Contracts14:22

Labels Applied

已应用标签

  • Finance/Invoices: 5 emails
  • Projects/Active: 12 emails
  • Clients/Priority: 8 emails
  • Finance/Invoices: 5封邮件
  • Projects/Active: 12封邮件
  • Clients/Priority: 8封邮件

Pending Actions

待处理事项

  • 3 emails require manual review
  • 2 large attachments need approval

---

*Gmail Workflows Skill - Part of Claude Office Skills*
  • 3封邮件需要人工审核
  • 2个大附件需要审批

---

*Gmail 工作流技能 - Claude 办公技能系列*