# Apple iCloud SMTP Delivery for Job Application Materials

When the user requests that job search results, cover letters, or application materials be emailed to them, use the Apple iCloud SMTP mechanism if credentials are available.

## Prerequisites

- `APPLE_EMAIL` environment variable set (e.g., sage.stockmans@icloud.com)
- `APPLE_APP_PASSWORD` environment variable set (app-specific password from appleid.apple.com)
- Generic sender script at `/home/thesage/.hermes/scripts/send_apple_email.py`

## SMTP Configuration

| Setting | Value |
|---------|-------|
| Host | `smtp.mail.me.com` |
| Port | `587` |
| Auth | `APPLE_EMAIL` + `APPLE_APP_PASSWORD` |
| Encryption | STARTTLS |

## Generic Sender Script

`/home/thesage/.hermes/scripts/send_apple_email.py` is a reusable script that accepts `--to`, `--subject`, `--body`, and `--html` flags. It reads credentials from env vars and sends via Apple SMTP.

### Usage

```bash
# Send plain text
python3 /home/thesage/.hermes/scripts/send_apple_email.py \
  --to sage.stockmans@pm.me \
  --subject "Job Search Results" \
  --body "Email content here"

# Send from stdin (useful for piping file contents)
cat results.txt | python3 /home/thesage/.hermes/scripts/send_apple_email.py \
  --to sage.stockmans@pm.me \
  --subject "Job Search Results" \
  --body -
```

### Piping File Contents

When emailing job search results or long text, pipe the file contents via stdin:

```bash
cat /home/thesage/job-search-results.txt | \
  python3 /home/thesage/.hermes/scripts/send_apple_email.py \
  --to sage.stockmans@pm.me \
  --subject "Job Search Results" \
  --body -
```

## Fallback

If Apple SMTP credentials are not configured, fall back to:
1. Saving results to a file and providing the absolute path
2. Drafting the email content for the user to send manually via ProtonMail

## Pitfalls

- Do NOT attempt to send email if `APPLE_EMAIL` or `APPLE_APP_PASSWORD` are not set. The script will exit with an error.
- The script defaults recipient to `sage.stockmans@pm.me` if `--to` is omitted.
- HTML emails: use `--html` flag, but prefer plain text for job search results to avoid spam filters.
