Skip to main content

Mailman Telegram Webhook

License: GPL v3 Code style black GitHub release PyPI version fury.io

Want to send message to telegram chats when receiving an email on a mailing list ? This script do it for you.

Installation

Installation procedure

It is possible to install the package via pip :

pip install mailman-telegram-webhook

but make sure to install it at good location. The config file is also downloaded with the python file.

Create the folder /usr/lib/python3/dist-packages/mailman_telegram_webhook and copy the __init__.py file inside.

You will need the python-telegram-bot package (as specified in the dependencies files).

Then copy the mailam-telegram-webhook.cfg file to /ect/mailman3 and edit it :

  • You need to set the token to a valid telegram bot token
  • If you want, you can specify a global chat id. Messages will be sent to this chat when the archiver is enabled for a mailing-list but no specific chat id is defined. If you leave this chat id empty, nothing happens when the archiver is enabled for a list without specific chat id.
  • You can specify specific chat id in [list.list_name] sections

Then copy the following code to mailman configuration (/etc/mailman3/mailman.cfg) :

[archiver.telegram_webhook]
class: mailman_telegram_webhook.Archiver
enable: yes
configuration: /etc/mailman3/mailman-telegram-webhook.cfg

Note : By default, the archiver will be enable on every list and if a global chat id is defined, messages will be sent from every list to this chat.

Configuration examples

[global]
token = 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
chat_id = 103

[list.contact]
chat_id = 104

We suppose that contact@my.domain and webmaster@my.domain have the archiver enabled and the token 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 (which is an example token) is associated to myBot.

  • A mail sent to contact@my.domain will make myBot send a message to the chat with id 104.
  • A mail sent to webmaster@my.domain will make myBot send a message to the the chat with id 103.
[global]
token = 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11

[list.contact]
chat_id = 104

We suppose that contact@my.domain and webmaster@my.domain have the archiver enabled and the token 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 (which is an example token) is associated to myBot.

Under the hood

This little script acts as an archiver (like Hyperkitty). When a message is received by mailman, if the archiver is configured and enabled on the mailing list, the message is passed to the archiver. The archive_function function just sends a message to telegram, according to the configuration.

The code is widely adapted from https://github.com/ondrejkolin/mailman_to_rocketchat and from Hyperkitty.

FAQ

How do I obtain a telegram bot token ?

You need to create a bot by speaking with @BotFather (see here for more information : https://core.telegram.org/bots)

How do I find chat ids ?

You can chat with some specific bots to find the chat id or you can use the bot you created. Invite him on the group or chat with him and take a look to https://api.telegram.org/bot<token>/getUpdates

What looks like the message on telegram ?

The message looks like New message from {from} to {to} : {subject}.

Example :

New message from Yoann Pietri <me@nanoy.fr> to webmaster@my.domain : [Webmaster] Unable to access website.

Can I change the message on telegram ?

No. You cannot change it in the configuration but you can edit the message in the __init__.py file, in the archive_message function.

Metadata

Release files for mailman-telegram-webhook 0.8.0

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

Source distribution (sdist)

Source distribution for mailman-telegram-webhook 0.8.0
File Size Uploaded Provenance
mailman_telegram_webhook-0.8.0.tar.gz 16.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mailman-telegram-webhook 0.8.0
File Interpreter ABI Platform
mailman_telegram_webhook-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / mailman_telegram_webhook-0.8.0.tar.gz

Download URL mailman_telegram_webhook-0.8.0.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
68a854164b2f339fc5e03dd71410741aaee4f50138347ccdf90de36de0dcda5c
BLAKE2b-256 checksum
How to use checksums
5aaf1cdf087b92972f2c68375d17c6d70d6a11810a5d6d91162591bac10f38da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.9 Linux/6.1.1-arch1-1

Release files / mailman_telegram_webhook-0.8.0-py3-none-any.whl

Download URL mailman_telegram_webhook-0.8.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48667ac73cee22a946f341ba5a4895a11356b53fb50bab2b381d608ab7e81a3d
BLAKE2b-256 checksum
How to use checksums
8d838b2473c14981542c42a4317a2ac384bbae747a15812efb3f3233ac132d52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.9 Linux/6.1.1-arch1-1

Security for mailman-telegram-webhook 0.8.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files No provenance

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