---
name: automating-mail
description: Automates Apple Mail via JXA with AppleScript dictionary discovery. Use when asked to "automate email", "send mail via script", "JXA Mail automation", or "filter email messages". Covers accounts, mailboxes, batch message filtering, composition, attachments, and UI fallback.
allowed-tools:
  - Bash
  - Read
  - Write
---

# Automating Apple Mail (JXA-first, AppleScript discovery)

## Contents
- [Relationship to macOS automation skill](#relationship-to-the-macos-automation-skill)
- [Core Framing](#core-framing)
- [Workflow](#workflow-default)
- [Quick Start Examples](#quick-start-examples)
- [Validation Checklist](#validation-checklist)
- [When Not to Use](#when-not-to-use)
- [What to load](#what-to-load)

## Relationship to the macOS automation skill
- Use `automating-mac-apps` for permissions, shell, and UI scripting guidance.
- **PyXA Installation:** See `automating-mac-apps` skill (PyXA Installation section).

## Core Framing
- Mail dictionary is AppleScript-first; discover in Script Editor.
- Objects are specifiers: read via method calls (`message.subject()`), modify via assignments (`message.readStatus = true`).
- ObjC bridge available for advanced filesystem operations.

## Workflow (default)
1) [ ] Ensure Mail configured and automation permissions enabled.
2) [ ] Discover terms in Script Editor (Mail dictionary).
3) [ ] Prototype minimal AppleScript command.
4) [ ] Port to JXA with defensive checks.
5) [ ] Use batch reads for performance.
6) [ ] Use UI scripting for signature and UI-only actions.

## Quick Start Examples

**Read inbox (JXA):**
```javascript
const Mail = Application('Mail');
const message = Mail.inbox.messages[0];
console.log(message.subject());
```

**Compose message (JXA):**
```javascript
const msg = Mail.OutgoingMessage({
  subject: "Status Update",
  content: "All systems go."
});
Mail.outgoingMessages.push(msg);
msg.visible = true;
```

**PyXA alternative:**
```python
import PyXA
mail = PyXA.Mail()
inbox = mail.inboxes()[0]
message = inbox.messages()[0]
print(f"Subject: {message.subject()}")
```

## Validation Checklist
- [ ] Automation permissions granted (System Settings > Privacy > Automation)
- [ ] Inbox access works: `Mail.inbox.messages.length`
- [ ] Message property reads return expected values
- [ ] Composition creates visible draft
- [ ] Batch operations complete without errors

## When Not to Use
- For cross-platform email automation (use IMAP/SMTP libraries)
- For bulk email sending (use transactional email services like SendGrid)
- When processing untrusted email content (security risk)
- For non-macOS platforms

## What to load
- Mail JXA basics: `automating-mail/references/mail-basics.md`
- Recipes (filter, move, compose): `automating-mail/references/mail-recipes.md`
- Advanced patterns (batch ops, HTML, signatures): `automating-mail/references/mail-advanced.md`
- Dictionary translation table: `automating-mail/references/mail-dictionary.md`
- Rule scripts: `automating-mail/references/mail-rules.md`
- HTML + signature workflow: `automating-mail/references/html-signature-workflow.md`
- Attachment extraction pipeline: `automating-mail/references/attachment-extraction.md`
- Mailbox archiver: `automating-mail/references/mailbox-archiver.md`
- HTML data merge: `automating-mail/references/html-data-merge.md`
- **PyXA API Reference** (complete class/method docs): `automating-mail/references/mail-pyxa-api-reference.md`

---
Source attribution: SpillwaveSolutions
Original project: https://github.com/SpillwaveSolutions/automating-mac-apps-plugin/blob/5f37bd4ecb1746fc86f3d618e8aa81fc6a61c486/plugins/automating-mac-apps-plugin/skills/automating-mail/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Dave AI.

## Upstream license notice

MIT License

Copyright (c) 2024 Richard Hightower

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Dave AI resource metadata

Creator / publisher: SpillwaveSolutions
Original project: https://github.com/SpillwaveSolutions/automating-mac-apps-plugin/blob/5f37bd4ecb1746fc86f3d618e8aa81fc6a61c486/plugins/automating-mac-apps-plugin/skills/automating-mail/SKILL.md
Attribution basis: Recovered original package and original project license at a pinned revision

Fields of work: Marketing, Sales, Customer Support
Roles: Customer Success Manager, Email Marketer, Support Agent
Specialties: API
Tools: Apple Mail, Applescript, Jxa
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: fead0181707634ad5142a72b20950f5f378e38f50a0b9f833a577ec25abd7907
Metadata reviewed: 2026-10-27
This metadata supersedes earlier Dave AI catalog attribution. Original instruction and supporting files are preserved.
