Mail2telegram
Forward email to telegram with Cloudflare Email Routing
Install / Use
/learn @tbxark/Mail2telegramREADME

This is a Telegram Bot based on Cloudflare Email Routing Worker, which can convert emails into Telegram messages. You can forward emails from recipients with any prefix to the Bot, and then a temporary mailbox Bot with an infinite address will be created.
<details> <summary>Click to view the demo.</summary> <img style="max-width: 600px;" alt="image" src="doc/example.png"> </details>Installation
0. Configure Telegram
- Create a bot to obtain a token, use
@BotFather > /newbot, create a bot and then copy the token. - Call
https://project_name.user_name.workers.dev/initto bind the Webhook, and check the returned result to confirm the binding status. - To use Telegram mini programs, you must set a privacy policy. Please visit
@BotFather > /mybots > (select one) > Edit Bot > Edit Privacy Policy, and then set it to the default privacy policy for Telegram mini programs:https://telegram.org/privacy-tpa
1. Deploy Workers
1.1 Deploy via Command Line
-
Clone the repository:
git clone git@github.com:TBXark/mail2telegram.git -
Copy the configuration template and modify it with your own Telegram configuration:
cp wrangler.example.jsonc wrangler.jsonc -
Deploy
yarn & yarn pub
1.2 Deploy via Copy and Paste
- If you don't want to deploy using the command line and prefer to copy and paste, you can use the precompiled version >
index.ts - When deploying via copy and paste, you need to manually set environment variables in the project's configuration page.
- Bind
KV Namespace Bindingsdatabase to worker with the nameDB - To generate a whitelist/blacklist of regular expressions as a JSON array string, you can use this small tool which also includes some demos: regexs2jsArray
2. Configure Cloudflare Email Routing
- Follow the official tutorial to configure Cloudflare Email Routing.
- Configure routing by changing the action of
Catch-all addressinEmail Routing - Routing RulestoSend to a Worker:mail2telegram. Forward all remaining emails to this worker. - If you set
Catch-all addressas workers, you won't be able to forward all remaining emails to your own email. If you need to backup emails, simply fill in your backup email in theFORWARD_LISTenvironment variable of the worker. - The email address in
FORWARD_LISTshould be added toCloudflare Dashboard - Email Routing - Destination addressesafter authentication in order to receive emails.
3. Binding a Telegram Webhook
Call https://project_name.user_name.workers.dev/init to bind the Webhook, check the return result to confirm the binding status.
Configuration
Location: Workers & Pages - your_work_name - Settings - Variables
| KEY | Description |
|:-----------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| TELEGRAM_ID | The Chat ID of the destination to sent by the Bot (such as your own Telegram account ID), can be obtained through the bot's /id command, which is generally a series of numbers, GROUP's start with -100. Multiple IDs separated by English commas |
| TELEGRAM_TOKEN | Telegram Bot Token e.g., 7123456780:AAjkLAbvSgDdfsDdfsaSK0 |
| DOMAIN | Workers domain name, e.g., project_name.user_name.workers.dev |
| FORWARD_LIST | Backup emails, can be forwarded to your own email for backup, leave blank if not forwarding, multiple values can be separated by , |
| ~~WHITE_LIST~~ | To be deprecated soon, switch to using built-in mini programs for editing.,Sender whitelist, an array of regular expressions or email address converted to a string, example: [\".*@10086\\\\.cn\"] |
| ~~BLOCK_LIST~~ | To be deprecated soon, switch to using built-in mini programs for editing.,Sender blacklist, an array of regular expressions or email address converted to a string |
| BLOCK_POLICY | Optional values reject,forward,telegram, Separated by commas. reject means to reject the email, forward means to don't forward mail to backup email, telegram means to don't send to telegram. Default is telegram |
| MAIL_TTL | Email cache retention time in seconds, default is one day. After expiration, emails will no longer be previewable, please back up. |
| WORKERS_AI_MODEL | Workers AI model identifier. When the Worker binds the AI service and this value is set, email summaries will use Workers AI. |
| OPENAI_API_KEY | OpenAI API Key, used for summarizing email content when Workers AI is not available. Without this and WORKERS_AI_MODEL, the "Summary" button will not appear. |
| OPENAI_COMPLETIONS_API | Customizable API, default value is https://api.openai.com/v1/chat/completions |
| OPENAI_CHAT_MODEL | Customizable model, default value is gpt-4o-mini |
| SUMMARY_TARGET_LANG | The language for customizing the summary, with a default value of english |
| GUARDIAN_MODE | Guard mode, default off, if you want to enable it, fill in true. |
| MAX_EMAIL_SIZE | Maximum email size in bytes, emails exceeding this size will be processed according to MAX_EMAIL_SIZE_POLICY. The main purpose is to prevent the worker function from timing out due to too large attachm
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
