apple-mail
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseApple Mail (Read Only)
Apple Mail (仅读取)
Read email via Mail.app AppleScript. No sending or modifying emails.
通过Mail.app的AppleScript读取邮件。不支持发送或修改邮件。
Prerequisites
前提条件
- Mail.app running and logged in
- Automation permissions granted (System Settings → Privacy & Security → Automation → Terminal/Claude Code → Mail)
- If first access attempt times out, ask user to check for macOS permission dialog
- 已运行Mail.app并登录账号
- 已授予自动化权限(系统设置→隐私与安全性→自动化→终端/Claude Code→Mail)
- 如果首次访问尝试超时,请让用户检查macOS权限对话框
Account & Machine Context
账号与设备上下文
See for which accounts are configured on which machines.
docs/email-accounts.md请查看了解各设备上配置的账号信息。
docs/email-accounts.mdCommands
命令
List accounts
列出账号
bash
osascript -e 'tell application "Mail" to get name of every account'bash
osascript -e 'tell application "Mail" to get name of every account'Count unread messages
统计未读邮件数量
bash
osascript -e 'tell application "Mail" to count (messages of inbox whose read status is false)'bash
osascript -e 'tell application "Mail" to count (messages of inbox whose read status is false)'Recent inbox messages (last 10)
收件箱最新邮件(最近10封)
bash
osascript -e 'tell application "Mail"
set recentMsgs to messages 1 thru 10 of inbox
repeat with msg in recentMsgs
set msgInfo to "From: " & (sender of msg) & " | Subject: " & (subject of msg) & " | Date: " & (date sent of msg)
log msgInfo
end repeat
end tell'bash
osascript -e 'tell application "Mail"
set recentMsgs to messages 1 thru 10 of inbox
repeat with msg in recentMsgs
set msgInfo to "From: " & (sender of msg) & " | Subject: " & (subject of msg) & " | Date: " & (date sent of msg)
log msgInfo
end repeat
end tell'Get message content by index
通过索引获取邮件内容
bash
osascript -e 'tell application "Mail"
set msg to message 1 of inbox
return "From: " & (sender of msg) & "\nSubject: " & (subject of msg) & "\nDate: " & (date sent of msg) & "\n\n" & (content of msg)
end tell'bash
osascript -e 'tell application "Mail"
set msg to message 1 of inbox
return "From: " & (sender of msg) & "\nSubject: " & (subject of msg) & "\nDate: " & (date sent of msg) & "\n\n" & (content of msg)
end tell'Search messages by subject
按主题搜索邮件
bash
osascript -e 'tell application "Mail"
set foundMsgs to (messages of inbox whose subject contains "keyword")
count foundMsgs
end tell'bash
osascript -e 'tell application "Mail"
set foundMsgs to (messages of inbox whose subject contains "keyword")
count foundMsgs
end tell'Search and read first match
搜索并读取首个匹配邮件
bash
osascript -e 'tell application "Mail"
set foundMsgs to (messages of inbox whose subject contains "keyword")
if (count foundMsgs) > 0 then
set msg to item 1 of foundMsgs
return "From: " & (sender of msg) & "\nSubject: " & (subject of msg) & "\nDate: " & (date sent of msg) & "\n\n" & (content of msg)
else
return "No messages found"
end if
end tell'bash
osascript -e 'tell application "Mail"
set foundMsgs to (messages of inbox whose subject contains "keyword")
if (count foundMsgs) > 0 then
set msg to item 1 of foundMsgs
return "From: " & (sender of msg) & "\nSubject: " & (subject of msg) & "\nDate: " & (date sent of msg) & "\n\n" & (content of msg)
else
return "No messages found"
end if
end tell'Search across all mailboxes
跨所有邮箱搜索
bash
osascript -e 'tell application "Mail"
set foundMsgs to (messages of every mailbox of every account whose subject contains "keyword")
-- Note: this can be slow across many accounts
end tell'bash
osascript -e 'tell application "Mail"
set foundMsgs to (messages of every mailbox of every account whose subject contains "keyword")
-- Note: this can be slow across many accounts
end tell'List mailboxes for an account
列出指定账号的邮箱
bash
osascript -e 'tell application "Mail" to get name of every mailbox of account "Gmail"'bash
osascript -e 'tell application "Mail" to get name of every mailbox of account "Gmail"'Notes
注意事项
- AppleScript returns a unified inbox across all accounts
messages of inbox - Messages are indexed newest-first (message 1 = most recent)
- returns plain text body;
content of msgreturns raw MIMEsource of msg - Large mailboxes can be slow — use clauses to filter
whose - Timeout: use for slow queries
with timeout of 60 seconds
- AppleScript的会返回所有账号的统一收件箱
messages of inbox - 邮件按最新到最旧排序(message 1 = 最新邮件)
- 返回纯文本正文;
content of msg返回原始MIME格式内容source of msg - 大型邮箱操作可能较慢——请使用子句进行过滤
whose - 超时处理:对于慢查询,可使用语句
with timeout of 60 seconds
Self-Improvement
自我优化
If you encounter an AppleScript pattern that fails, a macOS behavior change, or missing guidance in this skill, don't just work around it — fix the skill:
- Create a PR from a fresh worktree of on a new branch, fixing the issue directly
https://github.com/eins78/skills - Or file an issue on with: what failed, the actual behavior, and the suggested fix
https://github.com/eins78/skills
Never silently work around a skill gap. The fix benefits all future sessions.
如果您遇到AppleScript执行失败、macOS行为变更,或者本技能中缺少相关指引的情况,请不要仅仅采用临时解决方案——请修复本技能:
- 提交PR:从创建新分支的工作区,直接修复问题
https://github.com/eins78/skills - 或提交Issue:在上提交Issue,说明:失败内容、实际表现以及建议的修复方案
https://github.com/eins78/skills
请勿默默绕过技能缺陷。修复问题将使所有后续会话受益。