cloudflare-email-telegram-cursorrules-prompt-file — Cursor rule
Guides Cursor through setting up domain email forwarding to Telegram via Cloudflare Email Routing, Workers, and the mail2tg CLI.
.cursor/rules/cloudflare-email-telegram-cursorrules-prompt-file.mdcWhat cloudflare-email-telegram-cursorrules-prompt-file does
This rule guides the agent through deploying an email gateway with the mail2tg CLI. It prepares Cloudflare DNS with MX and SPF records, configures an Email Routing rule, and deploys an edge Worker. Incoming MIME messages, headers, and attachments up to 50 MB route straight to Telegram chats through the Bot API.
Setup requires Node.js 20 or newer, an active domain managed by Cloudflare DNS, and an API token. The token must include Zone Read, DNS Edit, Worker Scripts Edit, and Email Routing Rules Edit permissions. A Telegram bot token from @BotFather is also mandatory, and the recipient must trigger /start beforehand.
Once applied, zero code executes locally because the workload runs serverless on Cloudflare edge. Omitting the /start message to the Telegram bot causes the setup to fail with a missing chat ID error.
What it helps with
- forward domain emails directly to a Telegram chat
- configure Cloudflare MX and SPF records automatically
- deploy a serverless MIME parser on Cloudflare Workers
- send email attachments up to 50 MB to Telegram
Example prompts for the agent
- Set up email forwarding from my domain to Telegram using mail2tg
- Route incoming mail for [email protected] to Telegram via Cloudflare
- Run the mail2tg plan step for my Cloudflare zone
How to install cloudflare-email-telegram-cursorrules-prompt-file
Manually: put the files in place
.cursor/rules/cloudflare-email-telegram-cursorrules-prompt-file.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/cloudflare-email-telegram-cursorrules-prompt-file.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/cloudflare-email-telegram-cursorrules-prompt-file.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/cloudflare-email-telegram-cursorrules-prompt-file.mdManually: put the files in place
.clinerules/cloudflare-email-telegram-cursorrules-prompt-file.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about cloudflare-email-telegram-cursorrules-prompt-file
How to install cloudflare-email-telegram-cursorrules-prompt-file in Cursor?
Save the rule file to .cursor/rules/cloudflare-email-telegram-cursorrules-prompt-file.mdc in your repository.
What does cloudflare-email-telegram-cursorrules-prompt-file do?
It directs the IDE agent through initializing mail2tg, validating Cloudflare credentials, and deploying a Worker that pipes emails into Telegram.
What permissions does the Cloudflare API token need?
The token requires Zone Read, DNS Edit, Worker Scripts Edit, and Email Routing Rules Edit scopes.
Source text
cloudflare-email-telegram-cursorrules-prompt-file.mdc · CC0-1.0
--- description: "Cursor rules for setting up email-to-Telegram forwarding via Cloudflare Email Routing and Workers using the mail2tg CLI." globs: **/* alwaysApply: false --- You are an expert at setting up email-to-Telegram forwarding using Cloudflare Email Routing and Workers. When the user asks to set up email forwarding to Telegram, route domain email to Telegram, or mentions "mail2tg", "email to telegram", follow this workflow. ## Tool Use the `mail2tg` CLI published on npm: https://www.npmjs.com/package/mail2tg Source: https://github.com/shatzibitten/mail2tg ## Prerequisites 1. Domain DNS managed by Cloudflare (nameservers pointing to Cloudflare, status "Active"). 2. Cloudflare API token with scopes: Zone Read, DNS Edit, Worker Scripts Edit, Email Routing Rules Edit. Create at dash.cloudflare.com/profile/api-tokens → "Create Custom Token". 3. Telegram bot created via @BotFather, token copied. User has sent /start to the bot. 4. Node.js >= 20. ## Plan-first workflow ```bash export CLOUDFLARE_API_TOKEN="<token>" export TELEGRAM_BOT_TOKEN="<bot-token>" # Replace <reviewed-version> only after reviewing the npm package and source. MAIL2TG_DOMAIN=example.com \ [email protected] \ npx -y mail2tg@<reviewed-version> init --json npx -y mail2tg@<reviewed-version> plan --json # Stop here, show the plan to the user, and wait for explicit approval. npx -y mail2tg@<reviewed-version> apply --json npx -y mail2tg@<reviewed-version> doctor --json ``` ## Interactive workflow ```bash npx -y mail2tg@<reviewed-version> init export CLOUDFLARE_API_TOKEN="<token>" export TELEGRAM_BOT_TOKEN="<bot-token>" npx -y mail2tg@<reviewed-version> plan # Stop here, show the plan to the user, and wait for explicit approval. npx -y mail2tg@<reviewed-version> apply npx -y mail2tg@<reviewed-version> doctor ``` ## What it does - Deploys a Cloudflare Worker that parses incoming emails (MIME) and forwards headers, body, and attachments (up to 50 MB) to a Telegram chat via Bot API. - Creates MX and SPF DNS records so Cloudflare receives mail for the domain. - Creates an Email Routing rule directing the configured address to the Worker. - Sets Worker secrets (TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID). After apply, nothing runs locally. Everything is serverless on Cloudflare's edge. Free tier covers 100K emails/day. ## Exit codes - 0: success - 2: missing config or env vars - 3: Cloudflare/Telegram API error - 4: doctor checks failed - 5: worker deployment failed ## Common issues - "Telegram chat_id not found" → user must send /start to the bot, then re-run. - "Cloudflare zone not found" → domain not on Cloudflare or token lacks Zone Read scope. - "Worker deployment failed" → check internet; run `npx wrangler whoami` to debug.
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules