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.1.tar.gz (262.7 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.1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

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

Hashes for telegram_sendmail-1.2.1.tar.gz
Algorithm Hash digest
SHA256 5c6180a8520ed1a5bd559b8914c500cb046f03a844a310e9cebe2e70af0f2637
MD5 559e17d4d5d2edcb795ef831791f4632
BLAKE2b-256 b88481294cd9cf5af802aff098df6d3bd5cdea2a074caacd66db63239d01da1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for telegram_sendmail-1.2.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for telegram_sendmail-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 637f59cb71652e488bc049b1299a71a9739de1681fb7303463743972249ef090
MD5 f4a96b75b552e7660f6a38c0bc705b10
BLAKE2b-256 885304db5b457a3510334dd3f09944aebb697c30dbd129fa9272e5d522ac5ca0

See more details on using hashes here.

Provenance

The following attestation bundles were made for telegram_sendmail-1.2.1-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