云湖邮局开放版

这是一个众乐乐的版本,私人使用请看 使用云湖开放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)

8 个赞

感谢分享,留存备用。

没用过这个!

:ac01:感谢分享

不知道什么,点个赞

感谢分享

支持

1 个赞

暂时, 用不到, 顶一下.
(话说worker实现的发邮件会进垃圾箱吗?)

1 个赞

worker 自己发不了邮件,得靠第三方服务
至于进不进垃圾箱得看域名和第三方服务怎么样

2 个赞

感谢分享

1 个赞

那看来是我理解错了, 我还以为worker可以实现直接用Cloudflare的边缘节点发件 :ac01:
就像收件一样

1 个赞

厉害啊

1 个赞

这是啥,布置试试

1 个赞

感谢分享

感谢分享呀

1 个赞

问ai啊 就是建个邮箱,给每个人分配个邮箱地址,让大家一起使用,然后再app上接收消息,类似邮件接码

感谢分享

感谢分享

感谢分享