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 45b179ede3 Clean up unused code and config
Remove PROCESSED_FILE references and update .env.example with placeholder
Uptime URLs for privacy.

Changes:
- Remove unused processed_file variable and loading in main.py
- Update .env.example to use generic Uptime URLs
- Remove processed_uids.txt from .gitignore
2026-01-04 15:44:57 +09:00
email_forwarder.service.d Implement email forwarder 2026-01-04 15:34:31 +09:00
.env.example Clean up unused code and config 2026-01-04 15:44:57 +09:00
.gitignore Clean up unused code and config 2026-01-04 15:44:57 +09:00
email_forwarder-fail-notify.service Implement email forwarder 2026-01-04 15:34:31 +09:00
email_forwarder.service Implement email forwarder 2026-01-04 15:34:31 +09:00
email_forwarder.timer Implement email forwarder 2026-01-04 15:34:31 +09:00
main.py Clean up unused code and config 2026-01-04 15:44:57 +09:00
pyproject.toml Implement email forwarder 2026-01-04 15:34:31 +09:00
README.md Implement email forwarder 2026-01-04 15:34:31 +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 and using time-based searches.

Setup

  1. Copy .env.example to .env and fill in your IMAP credentials, Uptime URLs, and settings.

  2. Create virtual environment: python -m venv venv

  3. Activate and install: source venv/bin/activate && pip install -e .

  4. For user services (recommended):

    • Copy services: cp *.service *.timer ~/.config/systemd/user/
    • Copy drop-in: cp -r email_forwarder.service.d ~/.config/systemd/user/
    • Edit ~/.config/systemd/user/email_forwarder.service.d/override.conf to set PROJECT_DIR to your project path.
  5. Reload and enable: systemctl --user daemon-reload && systemctl --user enable email_forwarder.timer && systemctl --user start email_forwarder.timer

  6. Check status: systemctl --user status email_forwarder.timer

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
  • FOLDER: Mailbox folder (default INBOX)
  • 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}.

Dependencies

  • imaplib, email (built-in)
  • python-dotenv, imap-tools
  • systemd (for user services)

Troubleshooting

  • Logs: journalctl --user -u email_forwarder.service
  • Test: source venv/bin/activate && python main.py
  • Timezone issues: Adjust UTC offset in script if needed.