apple-mail

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Apple Mail Skill

Apple Mail 技能

This skill provides commands to interact with Apple Mail on macOS via AppleScript.
本技能提供了通过AppleScript在macOS上与Apple Mail交互的命令。

Available Scripts

可用脚本

All scripts are in the
../../scripts/
directory (relative to this file). Execute them via bash from the plugin root.
所有脚本都位于相对于本文件的
../../scripts/
目录中。从插件根目录通过bash执行它们。

Account & Mailbox Management

账户与邮箱管理

ScriptPurposeArguments
list-accounts.sh
List all email accountsnone
list-mailboxes.sh
List mailboxes/folders
[account]
(optional)
get-unread-count.sh
Get unread email count
[account] [mailbox]
(optional)
脚本用途参数
list-accounts.sh
列出所有邮箱账户
list-mailboxes.sh
列出邮箱/文件夹
[account]
(可选)
get-unread-count.sh
获取未读邮件数量
[account] [mailbox]
(可选)

Reading Emails

读取邮件

ScriptPurposeArguments
get-emails.sh
Get recent emails
[account] [mailbox] [limit] [include_content] [unread_only]
get-email-by-id.sh
Get specific email by ID
<id> [account] [mailbox] [include_content]
search-emails.sh
Search emails
<query> [account] [mailbox] [limit]
脚本用途参数
get-emails.sh
获取近期邮件
[account] [mailbox] [limit] [include_content] [unread_only]
get-email-by-id.sh
通过ID获取特定邮件
<id> [account] [mailbox] [include_content]
search-emails.sh
搜索邮件
<query> [account] [mailbox] [limit]

Sending & Composing

发送与撰写

ScriptPurposeArguments
send-email.sh
Send an email
<to> <subject> <body> [cc] [bcc] [from]
create-draft.sh
Create a draft email
<subject> <body> [to] [cc] [bcc] [from]
create-reply-draft.sh
Create reply to email
<message_id> <body> [reply_all] [account] [mailbox]
send-draft.sh
Send front-most draftnone
脚本用途参数
send-email.sh
发送邮件
<to> <subject> <body> [cc] [bcc] [from]
create-draft.sh
创建草稿邮件
<subject> <body> [to] [cc] [bcc] [from]
create-reply-draft.sh
创建邮件回复草稿
<message_id> <body> [reply_all] [account] [mailbox]
send-draft.sh
发送最前端的草稿

Email Management

邮件管理

ScriptPurposeArguments
archive-email.sh
Archive an email
<message_id> [account] [mailbox] [archive_mailbox]
delete-email.sh
Delete an email
<message_id> [account] [mailbox]
mark-read.sh
Mark email as read
<message_id> [account] [mailbox]
mark-unread.sh
Mark email as unread
<message_id> [account] [mailbox]
脚本用途参数
archive-email.sh
归档邮件
<message_id> [account] [mailbox] [archive_mailbox]
delete-email.sh
删除邮件
<message_id> [account] [mailbox]
mark-read.sh
标记邮件为已读
<message_id> [account] [mailbox]
mark-unread.sh
标记邮件为未读
<message_id> [account] [mailbox]

Output Format

输出格式

Scripts use delimiters for structured output:
  • <<>>
    separates fields within a record
  • |||
    separates multiple records
  • ERROR:
    prefix indicates an error message
脚本使用分隔符实现结构化输出:
  • <<>>
    分隔一条记录内的各个字段
  • |||
    分隔多条记录
  • ERROR:
    前缀表示错误信息

Email Record Format

邮件记录格式

id<<>>subject<<>>sender<<>>to<<>>cc<<>>bcc<<>>dateSent<<>>isRead<<>>content|||
id<<>>subject<<>>sender<<>>to<<>>cc<<>>bcc<<>>dateSent<<>>isRead<<>>content|||

Usage Examples

使用示例

List accounts

列出账户

bash
./scripts/list-accounts.sh
bash
./scripts/list-accounts.sh

Get recent emails from INBOX

获取收件箱中的近期邮件

bash
./scripts/get-emails.sh "" "INBOX" 10 false false
bash
./scripts/get-emails.sh "" "INBOX" 10 false false

Get recent unread emails with content

获取包含内容的近期未读邮件

bash
./scripts/get-emails.sh "" "INBOX" 10 true true
bash
./scripts/get-emails.sh "" "INBOX" 10 true true

Get specific email by ID

通过ID获取特定邮件

bash
./scripts/get-email-by-id.sh 12345 "iCloud" "INBOX" true
bash
./scripts/get-email-by-id.sh 12345 "iCloud" "INBOX" true

Search emails

搜索邮件

bash
./scripts/search-emails.sh "meeting notes" "" "" 20
bash
./scripts/search-emails.sh "meeting notes" "" "" 20

Send an email

发送邮件

bash
./scripts/send-email.sh "recipient@example.com" "Subject" "Body text"
bash
./scripts/send-email.sh "recipient@example.com" "Subject" "Body text"

Send with CC and BCC

发送带抄送和密送的邮件

bash
./scripts/send-email.sh "to@example.com" "Subject" "Body" "cc@example.com" "bcc@example.com"
bash
./scripts/send-email.sh "to@example.com" "Subject" "Body" "cc@example.com" "bcc@example.com"

Create a draft

创建草稿

bash
./scripts/create-draft.sh "Draft Subject" "Draft body" "recipient@example.com"
bash
./scripts/create-draft.sh "Draft Subject" "Draft body" "recipient@example.com"

Reply to an email

回复邮件

bash
./scripts/create-reply-draft.sh 12345 "Thanks for your message!" false "iCloud" "INBOX"
bash
./scripts/create-reply-draft.sh 12345 "Thanks for your message!" false "iCloud" "INBOX"

Send the front-most draft

发送最前端的草稿

bash
./scripts/send-draft.sh
bash
./scripts/send-draft.sh

Archive an email

归档邮件

bash
./scripts/archive-email.sh 12345 "iCloud" "INBOX"
bash
./scripts/archive-email.sh 12345 "iCloud" "INBOX"

Mark as read/unread

标记为已读/未读

bash
./scripts/mark-read.sh 12345 "iCloud" "INBOX"
./scripts/mark-unread.sh 12345 "iCloud" "INBOX"
bash
./scripts/mark-read.sh 12345 "iCloud" "INBOX"
./scripts/mark-unread.sh 12345 "iCloud" "INBOX"

Parsing Output

输出解析

When receiving email records, parse them like this:
  1. Split by
    |||
    to get individual records
  2. Split each record by
    <<>>
    to get fields
  3. Fields are: id, subject, sender, to, cc, bcc, dateSent, isRead, content
Example parsing in bash:
bash
IFS='|||' read -ra emails <<< "$output"
for email in "${emails[@]}"; do
    IFS='<<>>' read -ra fields <<< "$email"
    id="${fields[0]}"
    subject="${fields[1]}"
    sender="${fields[2]}"
    # ... etc
done
接收邮件记录时,可按以下方式解析:
  1. 使用
    |||
    分割以获取单个记录
  2. 使用
    <<>>
    分割每条记录以获取各个字段
  3. 字段依次为:id、subject、sender、to、cc、bcc、dateSent、isRead、content
Bash中的解析示例:
bash
IFS='|||' read -ra emails <<< "$output"
for email in "${emails[@]}"; do
    IFS='<<>>' read -ra fields <<< "$email"
    id="${fields[0]}"
    subject="${fields[1]}"
    sender="${fields[2]}"
    # ... 以此类推
done

Notes

注意事项

  • Scripts require macOS with Apple Mail configured
  • Apple Mail must have at least one account set up
  • First run may trigger macOS permission prompts for automation
  • Empty optional arguments should be passed as empty strings ""
  • For scripts that need arrays (multiple recipients), pass comma-separated values
  • 脚本需要配置好Apple Mail的macOS系统
  • Apple Mail必须至少设置一个账户
  • 首次运行可能会触发macOS的自动化权限提示
  • 可选参数为空时应传入空字符串""
  • 对于需要数组的脚本(如多个收件人),传入逗号分隔的值

Reference

参考资料

For advanced AppleScript patterns and customization, see
./reference/applescript-patterns.md
.
如需高级AppleScript模式和自定义内容,请查看
./reference/applescript-patterns.md