email-forwarder/README.md
Jeena a32f79980e Implement configurable STATE_DIR for state files
Move processed_message_ids.txt and last_run.txt to STATE_DIR,
configurable via .env. Install script creates ./state by default.

Changes:
- Add STATE_DIR to .env.example and config loading
- Update EmailForwarder to use os.path.join for file paths
- Add os.makedirs for state dir creation
- Update README with STATE_DIR option
2026-01-04 19:45:48 +09:00

43 lines
No EOL
1.6 KiB
Markdown

# Email Forwarder
This script forwards new emails from a source IMAP account (e.g., GMX) to a destination IMAP account (e.g., MXRoute), avoiding duplicates by tracking Message-IDs.
## Setup
Run the install script: `./install.sh`
This will set up the virtual environment, systemd services, and provide post-install instructions.
## Configuration (.env)
- `SOURCE_HOST`: Source IMAP server (e.g., imap.gmx.com)
- `SOURCE_PORT`: Port (default 993)
- `SOURCE_USER`: Source email/username
- `SOURCE_PASS`: Source password
- `DEST_HOST`: Destination IMAP server (e.g., yourserver.mxrouting.net)
- `DEST_PORT`: Port (default 993)
- `DEST_USER`: Destination email/username
- `DEST_PASS`: Destination password
- `FOLDERS`: Folders to sync (default "INBOX,Sent"; use "all" for all folders or comma-separated list)
- `STATE_DIR`: Directory for state files (default "./state")
- `DRY_RUN`: Set to `true` for testing without forwarding (default false)
- `UPTIME_SUCCESS_URL`: URL for success ping
- `UPTIME_FAIL_URL`: URL for failure ping
## How It Works
- Uses time-based search (`SINCE`) with `last_run.txt` to find emails since last run.
- Extracts Message-ID, checks against local file and destination IMAP for duplicates.
- Forwards via IMAP APPEND; updates `last_run.txt` on success.
- Logs activity; systemd handles Uptime Kuma pings.
## Monitoring with Uptime Kuma
- Success: Pings `${UPTIME_SUCCESS_URL}` after forwarding.
- Failure: `OnFailure` pings `${UPTIME_FAIL_URL}`.
## Troubleshooting
- Logs: `journalctl --user -u email_forwarder.service`
- Test: `source venv/bin/activate && python -m email_forwarder`
- Timezone issues: Adjust UTC offset in script if needed.