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.
Metadata
Release files for telegram-sendmail 1.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| telegram_sendmail-1.3.1.tar.gz | 269.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| telegram_sendmail-1.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 304.9 kB
Release files / telegram_sendmail-1.3.1.tar.gz
| Download URL | telegram_sendmail-1.3.1.tar.gz |
|---|---|
| Size | 269.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59a4e8b7565131154e1ac3e1be2641c53a28ccdfd53fc1e12b53d55b70205aa0
|
|
BLAKE2b-256 checksum How to use checksums |
daca36256894e22277f39006673f4e3a1b692d1de23b2844a64ff1603fe93a99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency logRelease files / telegram_sendmail-1.3.1-py3-none-any.whl
| Download URL | telegram_sendmail-1.3.1-py3-none-any.whl |
|---|---|
| Size | 35.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38d2274f5c0f9242a653b29ffeb4ddc8a9201b4edc8384165f984b70b0467af2
|
|
BLAKE2b-256 checksum How to use checksums |
569b0acfc684f340b4759c66262726de0a62da192d1950c480eae74971ee8f50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.
Transparency log