Email Forwarder is a Python-based tool that automates email synchronization between IMAP accounts (e.g., GMX to MXRoute). It forwards new emails, prevents duplicates using Message-ID tracking, supports multi-folder sync, and integrates with systemd for scheduled runs and Uptime Kuma monitoring.
Find a file
Jeena 05f2e6c870 Fail script on all server errors
Remove local exception handling for IMAP operations to ensure script
exits on any server failure (e.g., auth, connection, search errors).
This allows systemd OnFailure to notify on fixable issues.

Changes:
- Remove try-except in check_duplicate, sync_folder, sync_all_folders
- Let IMAP exceptions propagate to main() for exit(1)
2026-01-04 20:10:33 +09:00
email_forwarder Fail script on all server errors 2026-01-04 20:10:33 +09:00
.env.example Implement configurable STATE_DIR for state files 2026-01-04 19:45:48 +09:00
.gitignore Fix install script and update .gitignore 2026-01-04 17:46:16 +09:00
AGENTS.md Add AGENTS.md with project guidelines 2026-01-04 17:19:58 +09:00
email_forwarder-fail-notify.service Fix systemd variable expansion with shell wrapper 2026-01-04 18:53:06 +09:00
email_forwarder.service Add WorkingDirectory to systemd service 2026-01-04 19:55:27 +09:00
email_forwarder.timer Implement email forwarder 2026-01-04 15:34:31 +09:00
install.sh Remove drop-in config and use absolute paths in service file 2026-01-04 18:30:49 +09:00
pyproject.toml Restructure as runnable Python module 2026-01-04 18:22:42 +09:00
README.md Implement configurable STATE_DIR for state files 2026-01-04 19:45:48 +09:00

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.