Skip to content

Commit

Permalink
feat: add resend for send mail
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamhunter2333 committed May 26, 2024
1 parent dc14338 commit 64ee416
Show file tree
Hide file tree
Showing 15 changed files with 1,588 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- UI lazy load
- telegram bot 添加用户全局推送功能
- 增加对 cloudflare verified 用户发送邮件
- 增加使用 `resend` 发送邮件

## v0.4.4

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
</p>

> 本项目仅供学习和个人用途,请勿将其用于任何违法行为,否则后果自负。
>
> [Mail Channels 免费电子邮件发送 API 将于2024年6月30日结束](https://support.mailchannels.com/hc/en-us/articles/26814255454093-End-of-Life-Notice-Cloudflare-Workers)
>
> 正在集成 Resend 发送邮件
## [查看部署文档](https://temp-mail-docs.awsl.uk)

Expand Down
26 changes: 17 additions & 9 deletions frontend/src/components/SendBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ const refresh = async () => {
data.value = results.map((item) => {
try {
const data = JSON.parse(item.raw);
item.to_mail = data?.personalizations?.map(
(p) => p.to?.map((t) => t.email).join(',')
).join(';');
item.subject = data.subject;
item.contentType = data.content[0]?.type;
item.content = data.content[0]?.value;
item.raw = JSON.stringify(data, null, 2);
if (data.version == "v2") {
item.to_mail = data.to_name ? `${data.to_name} <${data.to_mail}>` : data.to_mail;
item.subject = data.subject;
item.is_html = data.is_html;
item.content = data.content;
item.raw = JSON.stringify(data, null, 2);
} else {
item.to_mail = data?.personalizations?.map(
(p) => p.to?.map((t) => t.email).join(',')
).join(';');
item.subject = data.subject;
item.is_html = (data.content[0]?.type != 'text/plain');
item.content = data.content[0]?.value;
item.raw = JSON.stringify(data, null, 2);
}
} catch (error) {
console.log(error);
}
Expand Down Expand Up @@ -160,7 +168,7 @@ onMounted(async () => {
</n-button>
</n-space>
<pre v-if="showCode" style="margin-top: 10px;">{{ curMail.raw }}</pre>
<pre v-else-if="curMail.contentType == 'text/plain'" style="margin-top: 10px;">{{ curMail.content }}</pre>
<pre v-else-if="!curMail.is_html" style="margin-top: 10px;">{{ curMail.content }}</pre>
<div v-else v-html="curMail.content" style="margin-top: 10px;"></div>
</n-card>
<n-card class="mail-item" v-else>
Expand Down Expand Up @@ -219,7 +227,7 @@ onMounted(async () => {
</n-tag>
</n-space>
<pre v-if="showCode" style="margin-top: 10px;">{{ curMail.raw }}</pre>
<pre v-else-if="curMail.contentType == 'text/plain'" style="margin-top: 10px;">{{ curMail.content }}</pre>
<pre v-else-if="!curMail.is_html" style="margin-top: 10px;">{{ curMail.content }}</pre>
<div v-else v-html="curMail.content" style="margin-top: 10px;"></div>
</n-card>
</n-drawer-content>
Expand Down
29 changes: 29 additions & 0 deletions vitepress-docs/docs/zh/guide/config-send-mail.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@

# 配置发送邮件

## 使用 Cloudflare Workers 给已认证的邮箱发送邮件

admin 后台 账号配置 `已验证地址列表(可通过 cf 内部 api 发送邮件)`

## 使用 resend 发送邮件

注册 `https://resend.com/domains` 根据提示添加 DNS 记录,

`API KEYS` 页面创建 `api key`

使用 cli 或者直接添加到 `wrangler.toml``vars`,或者在 cloudflare worker 页面的变量中添加 `RESEND_TOKEN`

```bash
wrangler secret put RESEND_TOKEN
```

如果你有多个域名,对应不同的 `api key`,可以在 `wrangler.toml` 中添加多个 secret, 名称为 `RESEND_TOKEN_` + `<. 换成 _ 的 大写域名>`,例如

```bash
wrangler secret put RESEND_TOKEN_XXX_COM
wrangler secret put RESEND_TOKEN_DREAMHUNTER2333_XYZ
```

## 使用 mailchannels 发送邮件

::: warning
[Mail Channels 免费电子邮件发送 API 将于2024年6月30日结束](https://support.mailchannels.com/hc/en-us/articles/26814255454093-End-of-Life-Notice-Cloudflare-Workers)
:::

1. 找到域名 `DNS` 记录的 `TXT``SPF` 记录, 增加 `include:relay.mailchannels.net`

`v=spf1 include:_spf.mx.cloudflare.net include:relay.mailchannels.net ~all`
Expand Down
19 changes: 19 additions & 0 deletions worker/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";


export default [
{
languageOptions: { globals: globals.browser },
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
}
}
];
6 changes: 6 additions & 0 deletions worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
"type": "module",
"scripts": {
"dev": "wrangler dev",
"lint": "eslint src",
"deploy": "wrangler deploy --minify",
"start": "wrangler dev",
"build": "wrangler deploy --dry-run --outdir dist --minify"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240512.0",
"@eslint/js": "8.56.0",
"eslint": "8.56.0",
"globals": "^15.3.0",
"typescript-eslint": "^7.10.0",
"wrangler": "^3.57.1"
},
"dependencies": {
"hono": "^4.3.9",
"mimetext": "^3.0.24",
"postal-mime": "^2.2.5",
"resend": "^3.2.0",
"telegraf": "4.16.3"
},
"pnpm": {
Expand Down
Loading

0 comments on commit 64ee416

Please sign in to comment.