A drop-in sendmail replacement that forwards system emails to Telegram.
Project description
Telegram Sendmail
telegram-sendmail replaces /usr/sbin/sendmail on Linux hosts that do
not need a full MTA. It accepts email input via the standard pipe interface
used by cron, logwatch, fail2ban, and other system daemons, converts it to
Telegram-compatible markup, and delivers it to a configured Telegram chat.
An SMTP server mode (-bs) is also provided for applications that speak
SMTP directly to the sendmail binary.
Features
- Zero data loss — every raw email is spooled to disk before any network call; if Telegram is unreachable, the original message is preserved.
- True drop-in — supports all
sendmailflags system daemons use in practice (-f,-r,-s,-bs,-t,-i,-oi) and ships as a standalone binary with no runtime dependencies. - Smart filtering — suppresses known-noisy messages via glob patterns
on
SubjectandFromheaders, keeping the chat focused on notifications that matter. - Retry-aware — exponential backoff on HTTP 429/5xx with
EX_TEMPFAIL(75) signalling so MTA-aware daemons re-queue automatically. - HTML-safe — two-pass sanitisation strips dangerous tags, converts safe markup to Telegram's HTML subset, detects attachments without forwarding binary content, and truncates long bodies at word boundaries.
- Observable — structured syslog output (
LOG_MAILfacility) with--consoleand--debugmodes for interactive diagnosis, and a--probeflag for post-deploy verification, suitable for provisioning pipelines and smoke tests.
Requirements
The standalone binary (available from GitHub Releases) has no runtime dependencies — Python is not required on the target host.
For PyPI installations, the following are required:
- Python 3.10 or later
- Runtime dependencies (installed automatically by
pip):
Quick Start
Installation
# Recommended: install with pipx for automatic isolation
pipx install telegram-sendmail
# Alternative: install into the system Python
pip install telegram-sendmail
Creating a Telegram Bot
- Open @BotFather in Telegram, send
/newbot, and follow the instructions. Copy the bot token it generates. - Send any message to the new bot or add it to a group or channel, then
visit
https://api.telegram.org/bot<TOKEN>/getUpdates. Thechat.idfield in the response provides the requiredchat_id.
Configuration
Create the configuration file with the two required keys:
sudo tee /etc/telegram-sendmail.ini > /dev/null << 'EOF'
[telegram]
token = 123456789:AAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
chat_id = -1001234567890
EOF
sudo chmod 600 /etc/telegram-sendmail.ini
sudo chown root:root /etc/telegram-sendmail.ini
The per-user path ~/.telegram-sendmail.ini is also supported and takes
precedence over the system-wide file when both are present.
Registering as the System sendmail
TGSM_BIN=$(which telegram-sendmail)
sudo ln -sf "$TGSM_BIN" /usr/sbin/sendmail
For the update-alternatives method (when an existing MTA is present), see
the User Guide.
Verifying the Installation
telegram-sendmail --probe --console --debug
Exit code 0 confirms end-to-end connectivity. 78 indicates a
configuration error, 75 a transient network failure, and 1 a permanent
API rejection.
Full Documentation
The complete user guide — covering all installation methods, the full configuration reference, SMTP server mode, the delivery pipeline, troubleshooting, and security hardening — is available in the GitHub repository.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telegram_sendmail-1.2.1.tar.gz.
File metadata
- Download URL: telegram_sendmail-1.2.1.tar.gz
- Upload date:
- Size: 262.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c6180a8520ed1a5bd559b8914c500cb046f03a844a310e9cebe2e70af0f2637
|
|
| MD5 |
559e17d4d5d2edcb795ef831791f4632
|
|
| BLAKE2b-256 |
b88481294cd9cf5af802aff098df6d3bd5cdea2a074caacd66db63239d01da1a
|
Provenance
The following attestation bundles were made for telegram_sendmail-1.2.1.tar.gz:
Publisher:
pypi.yml on theodiv/telegram-sendmail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telegram_sendmail-1.2.1.tar.gz -
Subject digest:
5c6180a8520ed1a5bd559b8914c500cb046f03a844a310e9cebe2e70af0f2637 - Sigstore transparency entry: 1155168462
- Sigstore integration time:
-
Permalink:
theodiv/telegram-sendmail@664d199d2c4431def4c2706b896181a93a7aaa03 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/theodiv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@664d199d2c4431def4c2706b896181a93a7aaa03 -
Trigger Event:
push
-
Statement type:
File details
Details for the file telegram_sendmail-1.2.1-py3-none-any.whl.
File metadata
- Download URL: telegram_sendmail-1.2.1-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
637f59cb71652e488bc049b1299a71a9739de1681fb7303463743972249ef090
|
|
| MD5 |
f4a96b75b552e7660f6a38c0bc705b10
|
|
| BLAKE2b-256 |
885304db5b457a3510334dd3f09944aebb697c30dbd129fa9272e5d522ac5ca0
|
Provenance
The following attestation bundles were made for telegram_sendmail-1.2.1-py3-none-any.whl:
Publisher:
pypi.yml on theodiv/telegram-sendmail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
telegram_sendmail-1.2.1-py3-none-any.whl -
Subject digest:
637f59cb71652e488bc049b1299a71a9739de1681fb7303463743972249ef090 - Sigstore transparency entry: 1155168471
- Sigstore integration time:
-
Permalink:
theodiv/telegram-sendmail@664d199d2c4431def4c2706b896181a93a7aaa03 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/theodiv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@664d199d2c4431def4c2706b896181a93a7aaa03 -
Trigger Event:
push
-
Statement type: