Skip to main content

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 sendmail flags 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 Subject and From headers, 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_MAIL facility) with --console and --debug modes for interactive diagnosis, and a --probe flag 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

  1. Open @BotFather in Telegram, send /newbot, and follow the instructions. Copy the bot token it generates.
  2. Send any message to the new bot or add it to a group or channel, then visit https://api.telegram.org/bot<TOKEN>/getUpdates. The chat.id field in the response provides the required chat_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.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telegram-sendmail 1.3.2
File Size Uploaded
telegram_sendmail-1.3.2.tar.gz 278.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-sendmail 1.3.2
File Interpreter ABI Platform
telegram_sendmail-1.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 315.7 kB

Release files / telegram_sendmail-1.3.2.tar.gz

Download URL telegram_sendmail-1.3.2.tar.gz
Size 278.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0fc8ec7133ef607792b137a865dc5c6f78b48d8ca5b6d251d46b64934e01e0b2
BLAKE2b-256 checksum
How to use checksums
39e321fbb0f94506a43447ec322bae393dd4f01ec0f457a10735952cde372703
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 14, 2026.

Transparency log

Release files / telegram_sendmail-1.3.2-py3-none-any.whl

Download URL telegram_sendmail-1.3.2-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acc884db08bd3c3ccdadde014f44f361b8c76f5edf2dca69708a302b92dd5b12
BLAKE2b-256 checksum
How to use checksums
7f6493aa3b55eed298e4e1f18f4649cce6752233fe2a448397b7d2c693709205
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 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page