Skip to main content
rule

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.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/cloudflare-email-telegram-cursorrules-prompt-file.mdc
Open on GitHub

What 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.mdc

Frontmatter: description, globs, alwaysApply

Step 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

Similar IDE rules

IDE rules catalog →

From the same set210

code-style-consistency-cursorrules-prompt-file A Cursor rule that makes the agent study your codebase conventions first and write new code to match them. Useful in repos with an established style. ★ 41,024repo stars code-pair-interviews Sets up Cursor for live coding interviews by enforcing plan outlines, simple initial solutions, clean naming, and edge-case handling. ★ 41,024repo stars code-guidelines-cursorrules-prompt-file A Cursor rule for careful code changes: verify facts, preserve existing structure, and account for tests, security, and version compatibility. ★ 41,024repo stars cloudflare-workers-hono-angular-saas-cursorrules-prompt-file A Cursor rule that pins the stack and conventions for SaaS on Cloudflare Workers: Hono API, Angular, Drizzle, Clerk, Stripe. ★ 41,024repo stars clean-code This rule sets practical standards for readable, maintainable code. Use it when an agent writes, reviews, or refactors files. ★ 41,024repo stars chrome-extension-dev-js-typescript-cursorrules-pro A Cursor rule that points the agent at one set of conventions for building Chrome extensions in JavaScript and TypeScript. ★ 41,024repo stars blender-python-addon Cursor rule for writing Blender Python add-ons. Enforces clean operator lifecycles, structured panels, and safe Blender API calls. ★ 41,024repo stars beefreesdk This Cursor rule sets out Beefree SDK installation, proxy authentication, UI container setup, configuration, and callbacks for web projects. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor