Cloudflare Email Routing 免费邮件发送(作为 Service 服务)用于 Workers/Pages 项目中。
如果您对本项目感兴趣,可以通过以下方式支持我:
Donation ways:
- Github: https://github.com/sponsors/willin
- Paypal: https://paypal.me/willinwang
- Alipay or Wechat Pay: QRCode
Apache-2.0
- 准备一个域名,例如
example.com
。现在,在 cloudflare-dashboard 中添加一个网站并构建您的域名。这可能需要大约 30 分钟。 - 选择您的站点和域名,启用电子邮件路由。这可能需要大约 5 分钟。
- 安装 wrangler 以部署 cf worker。确保您的 node 版本 >= 16.13.0 并运行:
npm install wrangler@latest -g
- 获取代码
git clone git@github.com:willin/cloudflare-send-email-service.git
- 部署您的 worker
# 建议改个名字
wrangler deploy --name send-email-worker-service
- 配置域名解析
创建第一个 TXT 解析记录:
- Name:
yourdomain.com
- Value:
v=spf1 a mx include:relay.mailchannels.net ~all
创建第二个 TXT 解析记录:
- Name:
_mailchannels.yourdomain.com
- Value:
v=mc1 cfid=yourdomain.workers.dev
(cfid
会在你测试的报错信息中看到,解析后等待生效大约需要半天)
更多关于 Domain Lockdown 错误的信息
- 设置 DKIM
这一步是可选的,但强烈推荐您去做。您可以参考 MailChannels 文档 步骤来完成域名的 DKIM 设置。
http://{{your-cf-worker-prefix}}.workers.dev/
POST
名称 | 类型 | 描述 |
---|---|---|
sender_email |
string |
发件人的电子邮件地址。 |
sender_name |
string |
发件人的名称。 |
recipient_email |
string |
收件人的电子邮件地址。 |
subject |
string |
电子邮件的主题。 |
message |
string |
电子邮件的正文。 |
curl -d"sender_email=admin@yourdomain.com&sender_name=Test&recipient_email=your-dest@example.com&subject='Hello Guy!'&message='My first email sent!'" "http://your-cf-worker-prefix.workers.dev/"
注意,端点 URL 中的 your-cf-worker-prefix
需要替换为实际的 worker 前缀。
A private api/worker service for sending email powered by Cloudflare worker project.
- Prepare a domian, such as
example.com
. Now, add a website in cloudflare-dashboard and build your domain. It maybe cost you about 30min. - Select your site and domain, Enable Email Routing. It maybe cost you about 5min.
- Install warngler for delpoy cf worker. Ensure your node version >= 16.13.0 and run :
npm install wrangler@latest -g
- Get the code
git clone git@github.com:willin/cloudflare-send-email-service.git
- Deploy your worker
wrangler deploy --name send-email-worker-service
- Config DNS records
Add a TXT record to your domain with the following values:
- Name:
yourdomain.com
- Value:
v=spf1 a mx include:relay.mailchannels.net ~all
Note: If you're facing Domain Lockdown error, follow the below steps:
- Name:
_mailchannels.yourdomain.com
- Value:
v=mc1 cfid=yourdomain.workers.dev
(the value ofcfid
will also be present in the error response)
- Setup DKIM
This step is optional, but highly recommended. DKIM is a DNS record that helps prevent email spoofing. You may follow the steps listed in the MailChannels documentation to set up DKIM for your domain.
http://{{your-cf-worker-prefix}}.workers.dev/
POST
Name | Type | Description |
---|---|---|
sender_email |
string |
The email address of the sender. |
sender_name |
string |
The name of the sender. |
recipient_email |
string |
The email address of the recipient. |
subject |
string |
The subject of the email. |
message |
string |
The message body of the email. |
curl -d"sender_email=admin@yourdomain.com&sender_name=Demo&recipient_email=your-dest@example.com&subject='Hello Guy!'&msg_data='My first email sent!'" "http://your-cf-worker-prefix.workers.dev/"