# Apple iCloud SMTP — Setup for Daily Briefing Email Delivery

Use your existing Apple ID to send briefing emails. This works with any iCloud/@me/@mac email.

## SMTP Settings

| Setting | Value |
|---------|-------|
| Host | `smtp.mail.me.com` |
| Port | `587` (STARTTLS) |
| Auth | Apple ID email + App-Specific Password |

## Required Environment Variables

Add to `~/.hermes/.env`:

```bash
APPLE_EMAIL="your@icloud.com"
APPLE_APP_PASSWORD="xxxx-xxxx-xxxx-xxxx"   # optional; falls back to a default
```

Make it private: `chmod 600 ~/.hermes/.env`

## App-Specific Password (Required)

1. Go to https://appleid.apple.com
2. Sign in → "Sign-In and Security" → "App-Specific Passwords"
3. Generate a new password (e.g., "DailyBriefing")
4. Copy the 4-group token — this is your `APPLE_APP_PASSWORD`

> **Do NOT use your main iCloud password.** Apple requires app-specific passwords for SMTP access.

## Reusing the Gmail Template

The `templates/gmail-smtp-delivery.py` template works for Apple with two changes:

1. Replace env var names: `GMAIL_USER` → `APPLE_EMAIL`, `GMAIL_APP_PASSWORD` → `APPLE_APP_PASSWORD`
2. Replace SMTP constants:
   ```python
   SMTP_HOST = "smtp.mail.me.com"
   SMTP_PORT = 587
   ```

Everything else (runner script, cron job, error handling) stays identical.

## Why Apple over Gmail?

- Reuses existing Apple Calendar credentials (`APPLE_EMAIL`, `APPLE_APP_PASSWORD`)
- No need to create a separate Gmail account or manage two credential sets
- Apple SMTP has generous daily limits for personal use

## Troubleshooting

| Symptom | Fix |
|---------|-----|
| "Authentication failed" | Verify you're using an **app-specific password**, not your Apple ID password |
| "Connection refused" | Check firewall; port 587 must be open for outbound STARTTLS |
| Email sent but not received | Check spam/junk; iCloud → ProtonMail sometimes gets filtered initially |

## Verification

```bash
set -a && source ~/.hermes/.env && set +a
python3 /home/$USER/.hermes/scripts/send_briefing_email.py
```
