Skip to content

Latest commit

 

History

History
75 lines (55 loc) · 1.87 KB

README.zh-cn.md

File metadata and controls

75 lines (55 loc) · 1.87 KB

Resend Cloudflare Worker Service

中文版 / English

准备工作

  1. Use this template 活 Fork 这个仓库来创建你的项目
  2. 在项目 Settings 里设置 Actions Secrets,添加如下环境变量:
### 仅用于 Github Actions
CLOUDFLARE_ACCOUNT_ID="xxx"
CLOUDFLARE_API_TOKEN="xxx"

### Resend 邮件发送服务,可自行注册免费发送
RESEND_API_KEY="re_xxxx"
### 发送邮件的用户名
EMAIL_USERNAME="No-Reply <[email protected]>"
### 发送测试邮件接收的地址
TEST_EMAIL_ADDRESS="[email protected]"

Worker / Pages 中使用

在项目工程中修改 wrangler.toml 配置,添加:

[[services]]
binding = "RESEND"
service = "email-sender-worker"

然后在代码中使用:

await ctx.env.RESEND.sendEmail({
  // 或者不用数组,直接一个邮箱字符串
  to: ['[email protected]'],
  subject: 'Hello, World!',
  html: '<h1>Hello, World!</h1>'
}); // 返回值类型为 boolean

其中 sendEmail 的参数为 SendEmailOptions 类型:

type SendEmailProps = {
  to: string | string[];
  subject: string;
  html: string;
};

本地开发测试

# 使用 npm、yarn 或者 pnpm 也可以
bun install
bun run dev

然后访问 http://localhost:8787 ,会给 TEST_EMAIL_ADDRESS 邮箱发送一封测试邮件。

赞助

如果您对本项目感兴趣,可以通过以下方式支持我:

  • 关注我的 Github 账号:@willin github
  • 参与 爱发电 计划
  • 支付宝或微信扫码打赏
  • ETH: 0x6D877f96198E55085CEb56097B099cc7bb814263

许可证

MIT