Skip to main content

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 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.

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

telegram_sendmail-1.2.2.tar.gz (264.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telegram_sendmail-1.2.2-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file telegram_sendmail-1.2.2.tar.gz.

File metadata

  • Download URL: telegram_sendmail-1.2.2.tar.gz
  • Upload date:
  • Size: 264.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for telegram_sendmail-1.2.2.tar.gz
Algorithm Hash digest
SHA256 f0821c8dc5638525fba123477fcade432c4cdada245ece58b78aea1ea0c509fa
MD5 4af5abf098770dfb8603071fc9b17613
BLAKE2b-256 b3da9378988e497dc61ec39b847f16a7a5e5cc7b27ea54eb51e82a21b2b0f056

See more details on using hashes here.

Provenance

The following attestation bundles were made for telegram_sendmail-1.2.2.tar.gz:

Publisher: pypi.yml on theodiv/telegram-sendmail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file telegram_sendmail-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_sendmail-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 58044ff99eaef3402fe3c80ac549bf4c4cfad7c1d3bce1b7af850a532c827a35
MD5 7ed96c8788a819f2580b7323bf6d0a45
BLAKE2b-256 5929e2994a2e215e1b7711fcfc9476bc07413d9a59638719b4964fc620a170ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for telegram_sendmail-1.2.2-py3-none-any.whl:

Publisher: pypi.yml on theodiv/telegram-sendmail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page