Forwards incoming emails to Telegram users/channels based on configurable routing rules. Built with Node.js.
npm install
cp .env.example .env
# Edit .env with your settings (optional, defaults work for local testing)
npm start- Web UI: http://127.0.0.1:3000
- SMTP server: port 2525 (configurable in .env)
- Open Telegram and chat with @BotFather
- Send
/newbotand follow the prompts to create a bot - Copy the bot token (looks like
123456789:ABCdefGHIJK...)
- Send any message to your new bot on Telegram
- Visit in your browser:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates - Look for
"chat":{"id":123456789}— that number is your chat ID - For groups, it's a negative number like
-1001234567890
Open the Web UI at http://127.0.0.1:3000:
- Bots tab — Add your bot token (name it whatever you like)
- Rules tab — Create a routing rule:
- Select the bot
- Enter the chat ID
- Set a sender pattern (e.g.,
*for all email,*@yourdomain.comfor a domain)
- Settings tab — Read the full configuration reference
Point any email client or script at your server:
# Using swaks (https://jetmore.org/john/code/swaks/)
swaks --to test@localhost --from [email protected] --server 127.0.0.1:2525 --body "Hello from SMTP2TG"If everything is configured correctly, the email appears in your Telegram chat.
| Variable | Default | Description |
|---|---|---|
WEB_PORT |
3000 | Web UI port |
WEB_HOST |
127.0.0.1 | Web UI bind address |
ADMIN_PASSWORD |
(none) | Optional password for web UI access |
SMTP_PORT |
2525 | SMTP server port |
SMTP_HOST |
0.0.0.0 | SMTP bind address |
SMTP_SECURE |
false | Use SMTPS (TLS on connect, port 465 style) |
SMTP_TLS_CERT |
(none) | Path to TLS certificate PEM file |
SMTP_TLS_KEY |
(none) | Path to TLS private key PEM file |
SMTP_AUTH_USERS |
(none) | Comma-separated user:pass pairs for SMTP auth |
SMTP_MAX_SIZE |
10485760 | Max email size in bytes (10MB) |
DEFAULT_BOT_ID |
(none) | Bot ID for wildcard catch-all forwarding |
DEFAULT_CHAT_ID |
(none) | Chat ID for wildcard catch-all forwarding |
SEVERITY_KEYWORDS |
(none) | Semicolon-separated severity:keyword groups |
- Plain SMTP (default): No TLS, no auth. Set
SMTP_PORT=25for standard. Only use on localhost or trusted networks. - STARTTLS: Set
SMTP_TLS_CERTandSMTP_TLS_KEYwithSMTP_SECURE=false. Offers opportunistic TLS on port 587. - SMTPS: Set
SMTP_SECURE=truewith cert and key. TLS required on connect (port 465 style). - With Auth: Add
SMTP_AUTH_USERS=user1:pass1,user2:pass2. Supports PLAIN and LOGIN auth.
Set DEFAULT_BOT_ID and DEFAULT_CHAT_ID in .env to forward all emails that don't match any explicit rule to a fallback chat. This acts as a catch-all — no rules needed. If both are set and a matching rule also exists, the email still goes to the rule destination (the wildcard only fires when zero rules match).
The server scans incoming email subjects and bodies for severity keywords and tags forwarded messages with visual indicators:
- 🔴 CRITICAL — breach, compromised, exploit, ransomware
- 🟠 HIGH — urgent, critical, alert, asap, immediate, incident
- 🟡 MEDIUM — warning, attention, notice
- 🟢 LOW — info, fyi, newsletter
Fully configurable via SEVERITY_KEYWORDS in .env. The highest-severity match wins and appears in the Telegram message header.
Rules use glob-style patterns matching against the sender's email address:
| Pattern | Matches |
|---|---|
* |
All senders (catch-all) |
*@example.com |
Anyone at example.com |
[email protected] |
Exact email match |
noreply@* |
noreply at any domain |
Matching is case-insensitive. All enabled matching rules fire, so a single email can be forwarded to multiple chats.
sudo bash install.shThis installs Node.js, copies the app to /opt/smtp2telegram, installs dependencies, creates a systemd service, and starts it.
sudo bash update.shCopies updated files, reinstalls deps, and restarts the service.
[Unit]
Description=SMTP to Telegram
After=network.target
[Service]
Type=simple
User=nobody
WorkingDirectory=/opt/smtp2telegram
ExecStart=/usr/bin/node server.js
Restart=on-failure
[Install]
WantedBy=multi-user.target- The web UI has no authentication by default. Set
ADMIN_PASSWORDin.envif exposing it beyond localhost. - When running without SMTP auth, bind to
127.0.0.1only (SMTP_HOST=127.0.0.1) to prevent open relay abuse. - Bot tokens are stored in the SQLite database. Restrict file access to the
data/directory. - Email content passes through your server — run it on infrastructure you control.