• Stars
    star
    218
  • Rank 181,805 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 1 year ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Forward email to telegram with Cloudflare Email Routing

mail2telegram


English | 中文

Use Telegram Bot to get your temporary email..

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.

Click to view the demo. image

Installation

1. Deploy Workers

1.1 Deploy via Command Line

  • Clone the repository:

    git clone [email protected]:TBXark/mail2telegram.git

  • Copy the configuration template and modify it with your own Telegram configuration:

    cp wrangler.example.toml wrangler.toml

  • 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.js
  • When deploying via copy and paste, you need to manually set environment variables in the project's configuration page.
  • 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 address in Email Routing - Routing Rules to Send to a Worker:mail2telegram. Forward all remaining emails to this worker.
  • If you set Catch-all address as 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 the FORWARD_LIST environment variable of the worker.

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

KEY Description
TELEGRAM_ID Your Telegram ID, pure numbers can be obtained through the /id command.
TELEGRAM_TOKEN Telegram Bot Token
DOMAIN Workers domain name, example: 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 Sender whitelist, an array of regular expressions converted to a string, example: [\".*@10086\\\\.cn\"]
BLOCK_LIST Sender blacklist, an array of regular expressions converted to a string
MAIL_TTL Email cache retention time in seconds, default is one day. After expiration, emails will no longer be previewable. Please make sure to back them up.
OPENAI_API_KEY OpenAI API Key, Used for summarizing email content. If not filled out, 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-3.5-turbo
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 attachments. Default is 512*1024.
MAX_EMAIL_SIZE_POLICY The available values are unhandled, truncate and continute. unhandled means return the headers without parsing the message body, truncate means truncate the message body and only parse the allowed size, continute means continue to process the message regardless of the size limit. The default is truncate. This policy only affects Telegram push messages, not email forwarding.
DB Bind KV Namespace Bindings database to worker with the name DB.

WHITE_LIST and BLOCK_LIST take effect on both recipients and senders at the same time, with WHITE_LIST having a higher priority than BLOCK_LIST.

The email address in FORWARD_LIST should be added to Cloudflare Dashboard - Email Routing - Destination addresses after authentication in order to receive emails.

Usage

The default message structure is as follows.

[Subject]

-----------
From : [sender]
To: [recipient]

(Preview)(Summary)(Text)(HTML)

When the email forwarding notification is sent to Telegram, only the title, sender, recipient, and four buttons are included.

Using Preview allows you to directly preview the plain text mode of the email in the bot. However, there is a limit of 4096 characters. If it exceeds 4096 characters, you can use TEXT or HTML to view the complete email. Below the preview message, there is a Back button that can be clicked to close the preview.

When you configure OPENAI_API_KEY, a Summary button will appear so that you can summarize the content of the email. Below the summary message, there is a Back button that can be clicked to close the summary.

Using TEXT, you can see plain text emails; using HTML, you can see rich-text emails. However, they may contain certain scripts or other tracking links. It is recommended to use rich-text mode only when necessary or when confirming that there are no issues with its source.

For security reasons, when exceeding the mail cache retention time (MAIL_TTL), links opened by buttons cannot be accessed. You can modify environment variables yourself to adjust expiration time.

This Bot does not support attachments. If you need attachment support, you can combine it with my another project testmail-viewer and forward emails to your testmail using FORWARD_LIST. This way, you can download your attachments using testmail-viewer.

Due to the limitation of Workers, if the email size (especially the attachment size) is too large, it will cause function timeout. At this time, Workers will retry multiple times, which may result in receiving multiple notifications and backup emails. Moreover, there is a limit on the number of retries. Once exceeded, no further retries will be made. This may lead to your email being lost. Therefore, it is recommended that you fill in your backup email in FORWARD_LIST, so that even if your email is lost, you can find it in your backup mailbox. If you frequently encounter this problem, you can try enabling Guardian Mode (GUARDIAN_MODE), which will record the operations already performed and not execute them again during the next retry. This reduces interference from duplicate messages and increases the success rate of workers. However, this operation consumes more KV write operations, so it is recommended to enable it when necessary.

License

mail2telegram is released under the MIT license. See LICENSE for details.

More Repositories

1

ChatGPT-Telegram-Workers

Deploy your own Telegram ChatGPT bot on Cloudflare Workers with ease.
TypeScript
3,466
star
2

TKRubberIndicator

A rubber animation pagecontrol
Swift
1,439
star
3

TKSwitcherCollection

An animation switch collection
Swift
914
star
4

PinterestSegment

A Pinterest-like segment control with masking animation.
Swift
687
star
5

Ruler

An AR ruler app can measure length & area
Swift
246
star
6

TKRadarChart

A customizable radar chart in Swift
Swift
210
star
7

TKDotSegment

TKDotSegment is a segment with dot animation
Swift
104
star
8

PasswordX

Offline password manager for iOS/macOS
Swift
29
star
9

tbxark.github.io

TBXark' blog
JavaScript
25
star
10

poe-telegram-bot

A lightweight poe chatbot for telegram
Python
18
star
11

shell-ask

Ask LLM directly from your terminal using a pure bash script
Shell
18
star
12

github-backup

A simple tool to backup github repository to gitea or other provider.
Go
16
star
13

ScrollViewThumbnail

Quickly create thumbnails for zoomed views in UIScrollview with just a single line of code.
Swift
14
star
14

g4vercel

Go web server for vercel
Go
10
star
15

TKSectorProgressView

An simple animation sector progress view
Swift
10
star
16

numberbarn2telegram

Forward the text message from NumberBarn to Telegram.
JavaScript
8
star
17

chatgpt-prompt-helper

A Tampermonkey script for quickly copying prompts in the web version of ChatGPT.
JavaScript
8
star
18

telegram-bot-vapor-example

Create telegram bot by swift
Swift
7
star
19

testmail-viewer

An online preview tool for Testmail.
Vue
6
star
20

JSONElement

JSONElement makes it easier and safer to use JSON
Swift
6
star
21

FlexLayout

Flex layout library similar to SwiftUI
Swift
6
star
22

chat-bot-go

A lightweight chatgpt bot for telegram
Go
5
star
23

SwiftCache

A pure swift cache framework
Swift
4
star
24

TrieRouter

A simple framework for application routing.
Swift
4
star
25

swift-telegram-bot-api

Swift Telegram Bot API and Telegram Bot API Generator
Swift
3
star
26

NetworkService

NetworkService with Alamofire and RxSwift
Swift
3
star
27

my-leetcode-code

LeetCode is a platform for preparing technical coding interviews.
Swift
3
star
28

vercel-proxy

Simple http proxy for Vercel.
Go
3
star
29

proxy-config-worker

[Deprecated] An online proxy configuration adaptation tool for Cloudflare worker.
JavaScript
2
star
30

autorun

autorun is a tool that listens for file changes and automatically executes commands.
Go
2
star
31

TBXark

Hi there, I'm TBXark~
2
star
32

rmock

Modify HTTP JSON responses without needing HTTP capture and MitM.
JavaScript
2
star
33

PiPlayground

可以由网页控制的提词器
Swift
2
star
34

RxSwiftLearnDemo

This is example code for RxSwift
Swift
2
star
35

MinesWeeping

A simple MinesWeeping Game
Swift
2
star
36

cloudflare-worker-adapter

Run your script without Cloudflare Workers.
TypeScript
2
star
37

gitea-mirror-reauth

Quickly modify the authorization information of a Gitea mirror repository.
Go
1
star
38

redmine-summary

redmine 周报生成工具
JavaScript
1
star
39

tic-tac

三子棋游戏,每人最多只能下三颗棋子,当下第四颗棋子时,最先那一颗棋子会消失
JavaScript
1
star
40

temporary-encrypted-clipboard

Clipboard encryption script for secure password transfer across devices.
JavaScript
1
star
41

dart_router

A simple framework for application routing.
Dart
1
star
42

mweb-export

A tool for generating directories from MWeb files.
Go
1
star
43

TKPlaceholderTextView

A textview with placeholder
Swift
1
star
44

Observable

A simple observer framework in Swift
Swift
1
star
45

Watermark

Swift
1
star
46

YoukuInfo

A simple youku crawler
HTML
1
star
47

azure2openai

A simple tool to proxy OpenAI‘s request to Azure OpenAI Service
Go
1
star
48

telegram-bot-workers-template

The basic template for running a Telegram Bot on Cloudflare Workers.
TypeScript
1
star