云湖邮局开放版
这是一个众乐乐的版本,私人使用请看 使用云湖开放API部署云湖邮局 | Runoneall
import PostalMime from "postal-mime";
async function parse(message) {
const message_from = message.from;
const message_to = message.to;
const infoHTML = `<div style="background-color: white; color: black;"><ul><li>From: ${message_from}</li><li>To: ${message_to}</li></ul>`;
const email = await PostalMime.parse(message.raw);
const email_subject = email.subject;
const email_content = email.html ?? email.text;
const contentHTML = `<details><summary><strong style="font-size: 20px;">${email_subject}</strong></summary>${email_content}</details></div>`;
return {
senderId: message_to.split("@")[0],
respHTML: infoHTML + `<hr>` + contentHTML,
};
}
async function response(YH_BOT_TOKEN, senderId, respHTML) {
await fetch(
`https://chat-go.jwzhd.com/open-apis/v1/bot/send?token=${YH_BOT_TOKEN}`,
{
method: "POST",
headers: { "Content-Type": "application/json; charset=utf-8" },
body: JSON.stringify({
recvId: senderId,
recvType: "user",
contentType: "html",
content: { text: respHTML },
}),
},
);
}
export default {
async email(message, env, ctx) {
const parsed = await parse(message);
await response(env.YH_BOT_TOKEN, parsed.senderId, parsed.respHTML);
},
};
完全公开需开启 Catch-All 功能,或者一个一个加记录使用白名单
支持多域名(能托管到 Cloudflare)