# Gmail SMTP Setup for Daily Briefings

## Overview
Deliver morning briefings (or any automated digest) via Gmail SMTP to any email address.

## Prerequisites

1. A Gmail account with **2-Factor Authentication enabled**
2. An **App Password** generated at https://myaccount.google.com/apppasswords
   - Select app: Mail
   - Select device: Other (custom name, e.g. "Hermes Briefing")
   - Copy the 16-character password (spaces are cosmetic — include or strip them)

## Env Vars

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

```bash
GMAIL_USER="your.email@gmail.com"
GMAIL_APP_PASSWORD=*** xxxx xxxx xxxx"
RECIPIENT="sage.stockmans@pm.me"
```

Lock the file:
```bash
chmod 600 ~/.hermes/.env
```

## Wiring into the Cron Job

Use a runner script that sources the `.env` file, then calls the Python sender:

```bash
#!/bin/bash
set -e
ENV_FILE="/home/$USER/.hermes/.env"
if [ -f "$ENV_FILE" ]; then
    set -a; source "$ENV_FILE"; set +a
fi
python3 /home/$USER/.hermes/scripts/send_briefing_email.py
```

Schedule via `cronjob` with `enabled_toolsets: ["terminal"]` — the script handles SMTP itself, so `send_message` is not needed.

## Common Issues

- **535-5.7.8 Authentication failed**: You used your main Gmail password instead of an App Password. Enable 2FA and generate an App Password.
- **SMTP connection refused / timeout**: Check firewall; port 587 must be reachable.
- **Redaction corrupts script files**: Hermes auto-redacts credential-like strings in tool outputs. Never paste real passwords into `write_file` or `execute_code` blocks. Always load from env vars. If you must patch a file that contains a password placeholder, use env-var substitution or base64-encoded placeholders to avoid literal matches.
