# Cron Job Email Delivery Workaround

## Problem
The `deliver` field on a cron job cannot be a raw email address. Setting `deliver: "sage.stockmans@pm.me"` results in:

```
last_delivery_error: "no delivery target resolved for deliver=sage.stockmans@pm.me"
```

Valid delivery targets are gateway-connected platforms like Telegram, Discord, Slack. On CLI sessions, `deliver: "local"` saves output but does not notify the user.

## Solution: Embed SMTP in the Prompt

Use `deliver: "local"` and `enabled_toolsets: ["terminal"]` on the cron job, then have the agent's prompt include instructions to send email via terminal.

### Apple iCloud SMTP Pattern

```python
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

APPLE_ID_PASSWORD = os.environ.get("APPLE_ID_PASSWORD")
APPLE_APP_PASSWORD = os.environ.get("APPLE_APP_PASSWORD")
SMTP_HOST = "smtp.mail.me.com"
SMTP_PORT = 587
FROM_EMAIL = "your_icloud@icloud.com"  # replace with actual
TO_EMAIL = "sage.stockmans@pm.me"

msg = MIMEMultipart()
msg["From"] = FROM_EMAIL
msg["To"] = TO_EMAIL
msg["Subject"] = "Weekly LinkedIn Tech Post Draft"
msg.attach(MIMEText(draft_content, "plain"))

server = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
server.starttls()
server.login(FROM_EMAIL, APPLE_APP_PASSWORD or APPLE_ID_PASSWORD)
server.send_message(msg)
server.quit()
```

### Cron Job Configuration

```json
{
  "schedule": "0 7 * * 1",
  "deliver": "local",
  "enabled_toolsets": ["terminal"],
  "prompt": "Research... After drafting, send via Apple iCloud SMTP using APPLE_APP_PASSWORD from env. Use smtplib. To: sage.stockmans@pm.me. If credentials missing, print draft to stdout and report failure."
}
```

## Fallover Behavior
Always include in the prompt: "If SMTP credentials are missing, print the draft to stdout and report the failure." This ensures the draft is not lost even if email sending fails.

## Related
- Morning Briefing job (job_id: 0ae7baffc114) uses this exact pattern successfully.
