Skip to content

About

Forward IMAP email (text, images, attachments) to a Telegram chat via your bot

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

GitHub Docker Hub Release CI Build Version Docker pulls Image size Platform Python Powered by MailToTelegramForwarder License

email2telegram

Email to Telegram forwarder docker service.

Source: GitHub · Images: Docker Hub, GHCR

It watches an IMAP mailbox and forwards new mails (text, HTML, embedded images and attachments) to a Telegram chat via your bot. Forwarded mails are marked as read in the mailbox.

Running the app

Images for amd64, arm64 and arm/v7 are published to Docker Hub and GitHub Container Registry.

docker run -d --restart unless-stopped \
    -e IMAP_SERVER=<Server address> \
    -e IMAP_USER=<Username> \
    -e IMAP_PASSWORD=<Password> \
    -e TELEGRAM_BOT_TOKEN=<Token> \
    -e TELEGRAM_CHAT_ID=<Chat ID> \
    -e MAIL_SUBJECT=<Subject to match> \
    -e CUT_FROM_SUBJECT="[Automation]" \
    fastiuk/email2telegram

Or with Docker Compose: copy .env.example to .env, fill it in and run docker compose up -d (see compose.yaml).

Settings

Variable Default Description
IMAP_SERVER required IMAP server, e.g. imap.gmail.com
IMAP_USER required IMAP login
IMAP_PASSWORD required IMAP password. For Gmail use an app password
TELEGRAM_BOT_TOKEN required Bot token from @BotFather
TELEGRAM_CHAT_ID required Chat or user ID to forward to, e.g. from @myidbot. Group IDs are negative
MAIL_SUBJECT Forward only mails whose subject contains this text
CUT_FROM_SUBJECT Text to remove from subjects, e.g. a common prefix of automated mails
FORWARD_MAIL_CONTENT True False sends only embedded images and attachments, with the subject as caption
FORWARD_ATTACHMENT True Forward attachments
FORWARD_EMBEDDED_IMAGES True Forward images embedded in HTML mails
PREFER_HTML True Use the HTML part of a mail rather than plain text
MAX_LENGTH 2000 Max length of forwarded mail text
IGNORE_INLINE_IMAGE Regular expression for inline images to skip, e.g. (spacer\.gif)
IMAP_PORT 993 IMAP port (TLS)
IMAP_FOLDER INBOX Mailbox folder to watch
IMAP_REFRESH 10 Polling interval in seconds
IMAP_SEARCH Custom IMAP search, replaces the one built from MAIL_SUBJECT. ${lastUID} is replaced with the last processed UID, e.g. (UID ${lastUID}:* UNSEEN FROM "alerts@example.com")
READ_OLD_MAILS False Kept for compatibility: unseen matching mails are always forwarded, including those received while the container was stopped

The required settings can also be read from files (Docker secrets) by adding a _FILE suffix, e.g. IMAP_PASSWORD_FILE=/run/secrets/imap_password.

Building docker image

The forwarder is a git submodule, so clone recursively:

git clone --recursive https://github.com/fastiuk/email2telegram.git
cd email2telegram
docker build -t email2telegram .

Testing

tests/e2e.sh runs the image against a GreenMail IMAP server and a Telegram Bot API mock, and checks what gets forwarded:

docker build -t email2telegram:test .
tests/e2e.sh email2telegram:test

Authors

License

This project and MailToTelegramForwarder are licensed under the GPLv3 License - see the LICENSE file for details.

Some parts (from IMAPBot) are licensed under the The MIT License (MIT) - see the LICENSE-MIT.md file for details.

About

Forward IMAP email (text, images, attachments) to a Telegram chat via your bot

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages