Lines of
README.md
from check-in 1723b63d69
that are changed by the sequence of edits moving toward
check-in 158c9cffc6:
1: # smtp2tg
2:
3: SMTP-to-Telegram gateway. Receives emails via SMTP and forwards them to Telegram chats.
4:
5: ---
6:
7: ## Installation
8:
9: ### From source
10: ```bash
11: git clone https://github.com/kworr/smtp2tg
12: cd smtp2tg
13: cargo build --release
14: ```
15:
16: ## Configuration
17:
18: 1. Create `smtp2tg.toml` (see `smtp2tg.toml.example` for reference).
19: 2. Get a Telegram Bot Token from [@BotFather](https://t.me/BotFather).
20: 3. Get your chat ID (use [@getidsbot](https://t.me/getidsbot) or debug mode in Telegram client).
21:
22: ### Example configuration
23: ```toml
24: api_key = "replace-with-your-telegram-bot-token"
25: api_gateway = "https://api.telegram.org"
26: listen_on = "127.0.0.1:1025"
1723b63d69 2026-08-01 27: unknown = "relay"
28: fields = ["date", "from", "subject"]
29: domains = ["example.com", "localhost"]
30:
31: default = 0
32:
33: [recipients]
34: "admin@example.com" = 12345678
35: "alerts@example.com" = -10012345678
36: ```
1723b63d69 2026-08-01 37:
1723b63d69 2026-08-01 38: To catch bounces (so they wouldn't stuck in upper mail server) make sure sender
1723b63d69 2026-08-01 39: envelope address is real as required by mail library (actually not sure whether
1723b63d69 2026-08-01 40: this applies to mailin). For example Postfix has to be tweaked like this:
1723b63d69 2026-08-01 41:
1723b63d69 2026-08-01 42: $config_directory/main.cf:
1723b63d69 2026-08-01 43: smtp_generic_maps = hash:$config_directory/generic
1723b63d69 2026-08-01 44:
1723b63d69 2026-08-01 45: $config_directory/generic:
1723b63d69 2026-08-01 46: "" postmaster@example.com
1723b63d69 2026-08-01 47: <> postmaster@example.com
1723b63d69 2026-08-01 48:
1723b63d69 2026-08-01 49: Actually not sure which one works...
50:
51: ---
52:
53: ## Usage
54:
55: ### Run
56: ```bash
57: ./smtp2tg -c /path/to/smtp2tg.toml
58: ```
59:
60: ### CLI arguments
61:
62: | Argument | Description | Example |
63: |---------------|---------------------------|-----------------------|
64: | `-h`, `--help` | Show help | `smtp2tg --help` |
65: | `-c`, `--config` | Path to config file | `smtp2tg -c config.toml` |
66:
67: ---
68:
69: ## Security
70:
71: ### Important
72: - **Recommended usage**: Run on `127.0.0.1` (localhost) only.
73: - If exposing to a network:
74: - **Restrict port access** via firewall.
75: - **Use TLS** (e.g., via `stunnel` or `nginx`).
76: - **Implement authentication** (this software does not provide it).
77:
78: ### Config file permissions
79: Set file permissions to `0600` (owner read/write only):
80: ```bash
81: chmod 600 smtp2tg.toml
82: ```
83:
84: ---
85: ## How it works
86: 1. A client (e.g., Postfix) sends an email to `listen_on` (e.g., `127.0.0.1:1025`).
87: 2. smtp2tg parses the email and converts it to a Telegram message.
88: 3. The message is sent to the specified chat (or `default` if address is unknown).
89:
90: ### Example: Email → Telegram
91: **Incoming email:**
92: ```text
93: From: user@example.com
94: To: admin@example.com
95: Subject: Test
96:
97: Hello, world!
98: ```
99:
100: **Telegram message:**
101: ```html
102: <blockquote expandable>
103: <u><i>Subject:</i></u> <code>Test</code>
104: <u><i>From:</i></u> <code>user@example.com</code>
105: <u><i>Date:</i></u> <code>Mon, 01 Jan 2024 12:00:00 +0000</code>
106: </blockquote>
107: <pre>Hello, world!</pre>
108: ```
109:
110: ---
111: ## Links
112: - **Original repository**: [http://fs.b1t.name/smtp2tg](http://fs.b1t.name/smtp2tg)
113: - **GitHub Mirror**: [https://github.com/kworr/smtp2tg](https://github.com/kworr/smtp2tg)