Sign inSign up

fastiuk/email2telegram

By fastiuk

โ€ขUpdated about 23 hours ago

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

Image
Internet of things
Monitoring & observability
0

1.7K

fastiuk/email2telegram repository overview

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
VariableDefaultDescription
IMAP_SERVERrequiredIMAP server, e.g. imap.gmail.com
IMAP_USERrequiredIMAP login
IMAP_PASSWORDrequiredIMAP password. For Gmail use an app passwordโ 
TELEGRAM_BOT_TOKENrequiredBot token from @BotFatherโ 
TELEGRAM_CHAT_IDrequiredChat or user ID to forward to, e.g. from @myidbotโ . Group IDs are negative
MAIL_SUBJECTForward only mails whose subject contains this text
CUT_FROM_SUBJECTText to remove from subjects, e.g. a common prefix of automated mails
FORWARD_MAIL_CONTENTTrueFalse sends only embedded images and attachments, with the subject as caption
FORWARD_ATTACHMENTTrueForward attachments
FORWARD_EMBEDDED_IMAGESTrueForward images embedded in HTML mails
PREFER_HTMLTrueUse the HTML part of a mail rather than plain text
MAX_LENGTH2000Max length of forwarded mail text
IGNORE_INLINE_IMAGERegular expression for inline images to skip, e.g. (spacer\.gif)
IMAP_PORT993IMAP port (TLS)
IMAP_FOLDERINBOXMailbox folder to watch
IMAP_REFRESH10Polling interval in seconds
IMAP_SEARCHCustom 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_MAILSFalseKept 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.

Tag summary

Content type

Image

Digest

sha256:f738ecdf8โ€ฆ

Size

44.4 MB

Last updated

5 days ago

docker pull fastiuk/email2telegram