File README.md artifact 3481cdb912 part of check-in 40a93e9a58
smtp2tg
SMTP-to-Telegram gateway. Receives emails via SMTP and forwards them to Telegram chats.
Installation
From source
git clone https://github.com/kworr/smtp2tg
cd smtp2tg
cargo build --release
Configuration
- Create
smtp2tg.toml(seesmtp2tg.toml.examplefor reference). - Get a Telegram Bot Token from @BotFather.
- Get your chat ID (use @getidsbot or debug mode in Telegram client).
Example configuration
api_key = "replace-with-your-telegram-bot-token"
api_gateway = "https://api.telegram.org"
listen_on = "127.0.0.1:1025"
fields = ["date", "from", "subject"]
domains = ["example.com", "localhost"]
default = 0
[recipients]
"admin@example.com" = 12345678
"alerts@example.com" = -10012345678
All recipients are internally lowercased, so UserName equals username.
Usage
Run
./smtp2tg -c /path/to/smtp2tg.toml
CLI arguments
| Argument | Description | Example |
|---|---|---|
-h, --help |
Show help | smtp2tg --help |
-c, --config |
Path to config file | smtp2tg -c config.toml |
Security
Important
- Recommended usage: Run on
127.0.0.1(localhost) only. - If exposing to a network:
- Restrict port access via firewall.
- Use TLS (e.g., via
stunnelornginx). - Implement authentication (this software does not provide it).
Config file permissions
Set file permissions to 0600 (owner read/write only):
chmod 600 smtp2tg.toml
How it works
- A client (e.g., Postfix) sends an email to
listen_on(e.g.,127.0.0.1:1025). - smtp2tg parses the email and converts it to a Telegram message.
- The message is sent to the specified chat (or
defaultif address is unknown).
Example: Email → Telegram
Incoming email: ```text From: user@example.com To: admin@example.com Subject: Test
Hello, world! ```
Telegram message:
<blockquote expandable>
<u><i>Subject:</i></u> <code>Test</code>
<u><i>From:</i></u> <code>user@example.com</code>
<u><i>Date:</i></u> <code>Mon, 01 Jan 2024 12:00:00 +0000</code>
</blockquote>
<pre>Hello, world!</pre>
Links
- Original repository: http://fs.b1t.name/smtp2tg
- GitHub Mirror: https://github.com/kworr/smtp2tg