apple-mail
AppleScriptを使ってApple Mailのメール読み込みや送信、メールボックス管理などを自動化する方法を包括的にガイドし、日々のメール業務を効率化するSkill。
📜 元の英語説明(参考)
Comprehensive guide for accessing and automating Apple Mail using AppleScript, including reading emails, sending messages, and managing mailboxes.
🇯🇵 日本人クリエイター向け解説
AppleScriptを使ってApple Mailのメール読み込みや送信、メールボックス管理などを自動化する方法を包括的にガイドし、日々のメール業務を効率化するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o apple-mail.zip https://jpskill.com/download/17519.zip && unzip -o apple-mail.zip && rm apple-mail.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17519.zip -OutFile "$d\apple-mail.zip"; Expand-Archive "$d\apple-mail.zip" -DestinationPath $d -Force; ri "$d\apple-mail.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
apple-mail.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
apple-mailフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Apple Mail AppleScript Skill
この skill は、AppleScript を使用して Apple Mail の操作を自動化するための包括的なガイダンスを提供します。これには、メールの読み取り、メッセージの送信、メールボックスの管理が含まれます。
コア原則
- アカウントオブジェクトを介してメールボックスにアクセスする - アカウントで直接
inboxにアクセスしようとしないでください - メールボックスを反復処理して適切なものを見つける - メールボックス名は異なる場合があります(INBOX、Inboxなど)
- アカウント名の一致を使用する - メールアドレスプロパティではなく、アカウント名で一致させます
- エラーを適切に処理する - AppleScript のエラーは不可解な場合があるため、さまざまなアプローチを試行錯誤して使用します
一般的なクエリパターン
1. すべてのメールアカウントをリストする
アカウントが存在することを確認し、正しい名前を取得するために、常にアカウントをリストすることから始めます。
osascript <<'EOF'
tell application "Mail"
set accountNames to {}
repeat with acc in accounts
set end of accountNames to (name of acc)
end repeat
return accountNames as string
end tell
EOF
出力例:
MonzoiCloudbrunofdcampos@gmail.commmbcfields@gmail.comcampos.bruno.fd@gmail.com
2. アカウントから最後の N 件のメールを読む
特定のアカウントからメールにアクセスするための正しいパターン:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set inboxMsgs to messages of mbox
set msgCount to count of inboxMsgs
set numToFetch to 5
if msgCount < 5 then set numToFetch to msgCount
set output to ""
repeat with i from 1 to numToFetch
set msg to item i of inboxMsgs
set output to output & "Email #" & i & return
set output to output & "Subject: " & subject of msg & return
set output to output & "From: " & sender of msg & return
set output to output & "Date: " & (date received of msg as string) & return
set output to output & return & "---" & return & return
end repeat
return output
end if
end repeat
return "Inbox not found"
end tell
EOF
試行錯誤からの重要な教訓:
- ❌ 間違い:
inbox of targetAccount(動作せず、エラー -1728 が発生します) - ❌ 間違い:
address of acc(address プロパティは確実には存在しません) - ✅ 正しい:
every mailbox of targetAccountを使用し、反復処理して "INBOX" または "Inbox" を見つけます
3. メールコンテンツを読む
特定のメールの本文全体を取得します。
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set msg to item 1 of messages of mbox
set emailContent to content of msg
return emailContent
end if
end repeat
end tell
EOF
4. メールを送信する
新しいメールを作成して送信します。
osascript <<'EOF'
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"Your Subject", content:"Your email body here", visible:true}
tell newMessage
make new to recipient at end of to recipients with properties {address:"recipient@example.com"}
send
end tell
end tell
EOF
オプション:
visible:true- 送信する前に作成ウィンドウを表示します(レビューに役立ちます)visible:false- バックグラウンドでサイレントに送信します
5. メールに返信する
既存のメールに返信します(スレッドを保持します)。
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
-- Find the message to reply to (e.g., by sender)
set foundMessages to (messages of mbox whose sender contains "sender@example.com")
set originalMsg to item 1 of foundMessages
-- Create reply
set theReply to reply originalMsg
tell theReply
set content to "Your reply message here"
send
end tell
return "Reply sent successfully"
end if
end repeat
end tell
EOF
重要なポイント:
- スレッド化された返信を作成するには、
reply originalMsgを使用します(make new outgoing messageではありません) replyコマンドは、受信者と件名を自動的に "Re:" で設定しますwith opening window falseパラメータは使用しないでください。構文エラーが発生します- 送信する前に、返信のコンテンツを設定します
返信 vs 新規メール:
- ❌ 間違い: 同じ受信者への新しいメッセージの作成(スレッドが中断されます)
set newMessage to make new outgoing message with properties {subject:"Re: Subject"} - ✅ 正しい: 元のメッセージで reply コマンドを使用する(スレッドを維持します)
set theReply to reply originalMsg
6. 件名でメールを検索する
件名のキーワードに一致するメールを検索します。
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set foundMessages to (messages of mbox whose subject contains "keyword")
set output to ""
repeat with msg in foundMessages
set output to output & "Subject: " & subject of msg & return
set output to output & "From: " & sender of msg & return
set output to output & "Date: " & (date received of msg as string) & return
set output to output & "---" & return
end repeat
retur
(原文がここで切り詰められています) 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Apple Mail AppleScript Skill
This skill provides comprehensive guidance on using AppleScript to automate Apple Mail operations, including reading emails, sending messages, and managing mailboxes.
Core Principles
- Access mailboxes through account objects - Don't try to access
inboxdirectly on accounts - Iterate through mailboxes to find the right one - Mailbox names can vary (INBOX, Inbox, etc.)
- Use account name matching - Match on account name rather than email address property
- Handle errors gracefully - AppleScript errors can be cryptic, use trial and error with different approaches
Common Query Patterns
1. List All Mail Accounts
Always start by listing accounts to verify the account exists and get the correct name:
osascript <<'EOF'
tell application "Mail"
set accountNames to {}
repeat with acc in accounts
set end of accountNames to (name of acc)
end repeat
return accountNames as string
end tell
EOF
Example output:
MonzoiCloudbrunofdcampos@gmail.commmbcfields@gmail.comcampos.bruno.fd@gmail.com
2. Read Last N Emails from an Account
The correct pattern for accessing emails from a specific account:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set inboxMsgs to messages of mbox
set msgCount to count of inboxMsgs
set numToFetch to 5
if msgCount < 5 then set numToFetch to msgCount
set output to ""
repeat with i from 1 to numToFetch
set msg to item i of inboxMsgs
set output to output & "Email #" & i & return
set output to output & "Subject: " & subject of msg & return
set output to output & "From: " & sender of msg & return
set output to output & "Date: " & (date received of msg as string) & return
set output to output & return & "---" & return & return
end repeat
return output
end if
end repeat
return "Inbox not found"
end tell
EOF
Key lessons from trial and error:
- ❌ WRONG:
inbox of targetAccount(doesn't work, causes error -1728) - ❌ WRONG:
address of acc(address property doesn't exist reliably) - ✅ CORRECT:
every mailbox of targetAccountthen iterate to find "INBOX" or "Inbox"
3. Read Email Content
Get the full body content of a specific email:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set msg to item 1 of messages of mbox
set emailContent to content of msg
return emailContent
end if
end repeat
end tell
EOF
4. Send an Email
Create and send a new email:
osascript <<'EOF'
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"Your Subject", content:"Your email body here", visible:true}
tell newMessage
make new to recipient at end of to recipients with properties {address:"recipient@example.com"}
send
end tell
end tell
EOF
Options:
visible:true- Shows the compose window before sending (useful for review)visible:false- Sends silently in the background
5. Reply to an Email
Reply to an existing email (preserves threading):
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
-- Find the message to reply to (e.g., by sender)
set foundMessages to (messages of mbox whose sender contains "sender@example.com")
set originalMsg to item 1 of foundMessages
-- Create reply
set theReply to reply originalMsg
tell theReply
set content to "Your reply message here"
send
end tell
return "Reply sent successfully"
end if
end repeat
end tell
EOF
Key points:
- Use
reply originalMsgto create a threaded reply (NOTmake new outgoing message) - The
replycommand automatically sets the recipient and subject with "Re:" - Don't use
with opening window falseparameter, it causes syntax errors - Set the content of the reply before sending
Reply vs New Email:
- ❌ WRONG: Creating new message to same recipient (breaks threading)
set newMessage to make new outgoing message with properties {subject:"Re: Subject"} - ✅ CORRECT: Using reply command on original message (maintains threading)
set theReply to reply originalMsg
6. Search Emails by Subject
Find emails matching a subject keyword:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set foundMessages to (messages of mbox whose subject contains "keyword")
set output to ""
repeat with msg in foundMessages
set output to output & "Subject: " & subject of msg & return
set output to output & "From: " & sender of msg & return
set output to output & "Date: " & (date received of msg as string) & return
set output to output & "---" & return
end repeat
return output
end if
end repeat
end tell
EOF
7. Search Emails by Sender
Find all emails from a specific sender:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set foundMessages to (messages of mbox whose sender contains "sender@example.com")
set output to "Found " & (count of foundMessages) & " messages" & return & return
repeat with msg in foundMessages
set output to output & subject of msg & return
end repeat
return output
end if
end repeat
end tell
EOF
8. Get Email Metadata Without Content
Get subject, sender, and date without loading full content (faster):
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set recentMsgs to items 1 thru 10 of messages of mbox
set output to ""
repeat with msg in recentMsgs
set output to output & subject of msg & " | " & sender of msg & return
end repeat
return output
end if
end repeat
end tell
EOF
9. Check Unread Message Count
Count unread messages in inbox:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set unreadCount to count of (messages of mbox whose read status is false)
return "Unread messages: " & unreadCount
end if
end repeat
end tell
EOF
10. Move Email to Mailbox
Move a message to a different mailbox:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
-- Find the source mailbox
repeat with mbox in allMailboxes
if name of mbox is "INBOX" then
set theMessage to item 1 of messages of mbox
-- Find the destination mailbox
repeat with destBox in allMailboxes
if name of destBox is "Archive" then
move theMessage to destBox
return "Message moved to Archive"
end if
end repeat
end if
end repeat
end tell
EOF
11. Delete Emails by Criteria
Delete emails matching specific criteria:
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" then
set messagesToDelete to (messages of mbox whose subject contains "spam")
repeat with msg in messagesToDelete
delete msg
end repeat
return "Deleted " & (count of messagesToDelete) & " messages"
end if
end repeat
end tell
EOF
Common Mailbox Names
Different email providers use different mailbox names:
Gmail Accounts
INBOX- Main inbox[Gmail]/All Mail- All mail archive[Gmail]/Sent Mail- Sent messages[Gmail]/Trash- Deleted items[Gmail]/Drafts- Draft messages[Gmail]/Spam- Spam folder
iCloud Accounts
Inbox- Main inbox (note the capitalisation)Sent Messages- Sent mailTrash- Deleted itemsDrafts- Draft messages
Other Providers
- May use
Sent Items,Deleted Items, etc. - Always iterate through mailboxes and check names
Email Message Properties
Common properties you can access on a message object:
subject of msg -- Email subject line
sender of msg -- Sender email address
date received of msg -- Date the email was received
date sent of msg -- Date the email was sent
content of msg -- Full email body (can be slow)
read status of msg -- Boolean: true if read, false if unread
flagged status of msg -- Boolean: true if flagged/starred
message id of msg -- Unique message identifier
to recipients of msg -- List of recipient objects
cc recipients of msg -- List of CC recipient objects
all headers of msg -- Raw email headers
message size of msg -- Size in bytes
Error Handling
Common Errors and Solutions
Error: "Can't get inbox of account"
-- ❌ WRONG: Trying to access inbox directly
tell application "Mail"
set targetAccount to account "email@example.com"
set inboxMsgs to messages of inbox of targetAccount -- This fails!
end tell
-- ✅ CORRECT: Iterate through mailboxes
tell application "Mail"
set targetAccount to account "email@example.com"
set allMailboxes to every mailbox of targetAccount
repeat with mbox in allMailboxes
if name of mbox is "INBOX" or name of mbox is "Inbox" then
set inboxMsgs to messages of mbox
end if
end repeat
end tell
Error: "Can't get address of account"
-- ❌ WRONG: address property is unreliable
if address of acc contains "email@example.com" then
-- ✅ CORRECT: Use name property instead
if name of acc contains "email@example.com" then
Error: "Can't get item 1 of every account"
-- ❌ WRONG: Don't try to access properties in bulk operations
repeat with acc in accounts
if address of acc contains "..." then -- This fails!
-- ✅ CORRECT: Get properties individually
repeat with acc in accounts
set accName to name of acc
if accName contains "..." then
Error: Message not found or mailbox doesn't exist
-- Solution: Always check existence first
set allMailboxes to every mailbox of targetAccount
if (count of allMailboxes) = 0 then
return "No mailboxes found for this account"
end if
Best Practices
-
Always list accounts first when debugging:
osascript -e 'tell application "Mail" to name of every account' -
Check mailbox names before accessing:
set mailboxNames to name of every mailbox of targetAccount -
Use heredoc syntax for multi-line AppleScript in bash:
osascript <<'EOF' tell application "Mail" -- Your script here end tell EOF -
Handle case sensitivity in mailbox names:
if name of mbox is "INBOX" or name of mbox is "Inbox" then -
Limit message retrieval to avoid slowdowns:
set recentMsgs to items 1 thru 10 of messages of mbox -
Check message count before iterating:
set msgCount to count of messages of mbox if msgCount < numToFetch then set numToFetch to msgCount -
Use
returnearly when you find what you need:repeat with mbox in allMailboxes if name of mbox is "INBOX" then -- Process and return return result end if end repeat
Performance Tips
- Don't load content unnecessarily - Getting
content of msgis slow - Limit the number of messages processed in one script
- Use filters (
whoseclauses) to narrow results before processing - Cache mailbox references if doing multiple operations
Security and Privacy Considerations
- Mail access requires permissions - macOS will prompt for access on first use
- Be careful with automation - Test sending scripts with visible:true first
- Respect user privacy - Don't log sensitive email content
- Use specific searches - Avoid processing entire mailboxes when possible
Quick Reference Commands
# List all accounts
osascript -e 'tell application "Mail" to name of every account'
# Get inbox message count for an account
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
repeat with mbox in mailboxes of targetAccount
if name of mbox is "INBOX" or name of mbox is "Inbox" then
return count of messages of mbox
end if
end repeat
end tell
EOF
# Get unread count
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
repeat with mbox in mailboxes of targetAccount
if name of mbox is "INBOX" then
return count of (messages of mbox whose read status is false)
end if
end repeat
end tell
EOF
# List all mailbox names for an account
osascript <<'EOF'
tell application "Mail"
set targetAccount to account "email@example.com"
set mailboxNames to name of every mailbox of targetAccount
return mailboxNames as string
end tell
EOF
When to Use This Skill
Invoke this skill when you need to:
- Read emails from Apple Mail
- Send automated emails
- Reply to emails (maintaining thread context)
- Search for specific emails
- Manage mailboxes programmatically
- Count unread messages
- Move or delete emails based on criteria
- Extract email metadata
- Automate email workflows
Integration with Other Workflows
When working with email automation:
- Email notifications - Send alerts when specific events occur
- Data extraction - Parse emails for specific information
- Email filtering - Auto-file or delete emails based on rules
- Reporting - Generate summaries of email activity
- Backup - Export email data for archival
Lessons Learned (Trial and Error)
The key insights from developing this skill:
- Don't use
inbox of accountdirectly - Always iterate through mailboxes - Account properties vary - Use
namenotaddress - Mailbox names vary by provider - Check for both "INBOX" and "Inbox"
- Error -1728 usually means property doesn't exist - Try a different property
- Bulk operations on
every Xcan fail - Get properties individually - Use
items 1 thru Nfor safe list slicing with bounds checking - Use
replycommand, not new messages - To maintain threading, usereply originalMsginstead of creating a new outgoing message - Don't use
with opening windowparameter - Thereplycommand doesn't support thewith opening window falseparameter, causes syntax errors
Remember: AppleScript error messages are often cryptic. When debugging, simplify the script to the minimum necessary and build up complexity gradually.