Skip to content

necto/kmail-alias-bot

Repository files navigation

kMail-alias Telegram Bot

A simple Telegram bot that facilitates management of e-mail aliases in Infomaniak’s kMail on your proper domain.

kMail supports up to 50 aliases in the free plan (kSuite Standard) for a single-user e-mail on your own custom domain.

Features

  • Communicates with a single pre-configured telegram user based on their telegram user ID. You don’t want random strangers to manage your e-mail aliases, so set the id to your user. You can get your user id from a user-id bot, or just by running this bot with a wrong user-id configured and sending it a message. It will respond to you with your user id. For example:

    Unauthorized user 123456789, please contact the administrator

    then add “123456789” as the authorized_user_id in your kmail-alias.toml config.

  • /add command to create an alias.
    • Accepts alias name (before ‘@’ part) description (purpose)
    • In addition to creating the alias, also sends a test e-mail to the newly created address, with the provided description. This serves a double purpose of documenting the alias itself
  • /list command to list all the aliases
  • /remove command to remove an alias
  • You can deploy this application using docker. See example NAS compose file for inspiration.

Prerequisites

Given that it is a Telegram bot, it requires a Telegram token to operate. You can get the token by creating a new bot using the @BotFather Telegram bot.

An Infomaniak API access token. You need access to the kMail aliases feature. I use it with my own custom domain. The free version includes up to 50 aliases, that I can add and remove at a whim. Follow their official documentation. You need the mail scope.

SMTP-client credentials. You need to open access to one of your existing e-mail accounts to enable the bot send probe e-mails on your behalf to the newly created alias. I used my gmail account. See “Option 2: Send email with the Gmail SMTP server” in this official manual. You’ll most likely want to crate an “App password” (in Account settings / Security / 2-Step Verification).

Installation and running

You have multiple options to use this application. In any case, you’ll need to run it on a host that has access to the internet. It can run perfectly fine behind a NAS, you don’t need to expose anything, as it only accesses public APIs. For it to be useful, you’ll need to run it continuously, so something like a cloud instance or a NAS would be ideal.

Docker

Assuming your configuration file is “./kmail-alias.toml”, you can run it directly with

docker run -it --rm --mount type=bind,src=./kmail-alias.toml,dst=/kmail-alias.toml,ro azaostro/kmail-alias-bot

Or as a long-running Docker Compose service, using docker-compose.yml :

docker compose up

The above commands use the published container image from the Docker Hub.

Cargo

cargo install kmail-alias-bot

Will install it into the default location where Cargo keeps executables, e.g. ”/.cargo/bin". Once it is in your ~$PATH, and you have “kmail-alias.toml” file in your local directory, you can run it simply with

kmail-alias-bot

Guix

You can use the prepared package definition with all the dependencies not defined in the Guix master channel:

guix shell -f guix-package.scm -- kmail-alias-bot

Git clone

Finally, you can run the application directly from the repository clone, make sure you have OpenSSL and PKG-config installed, for example, with guix:

guix shell rust rust-cargo openssl pkg-config
RUST_LOG=debug cargo run

Configuration

Copy test configuration file as ./kmail-alias.toml and follow the comments to adjust the configuration values.

Building the image

I use Guix pack to prepare a docker image that I then deploy on my QNAP NAS Container Station:

guix pack --format=docker --file=guix-package.scm --entry-point=bin/kmail-alias-bot --root=docker-image.tar.gz
docker load < docker-image.tar.gz
docker tag rust-kmail-alias-bot azaostro/kmail-alias-bot:latest

Finally, to push it to Docker Hub:

docker login
docker push azaostro/kmail-alias-bot:latest