Forward IMAP email (text, images, attachments) to a Telegram chat via your bot
1.7K
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.
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โ ).
| 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 "[email protected]") | |
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.
The forwarder is a git submodule, so clone recursively:
git clone --recursive https://github.com/fastiuk/email2telegram.git
cd email2telegram
docker build -t email2telegram .
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
Awalon - The core service MailToTelegramForwarder - Awalon/MailToTelegramForwarderโ (used via the fastiuk/MailToTelegramForwarderโ fork)
Yevhen Fastiuk - email2telegram Docker wrapper - @fastiukโ
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.
Content type
Image
Digest
sha256:f738ecdf8โฆ
Size
44.4 MB
Last updated
5 days ago
docker pull fastiuk/email2telegram