2026-10-05 07:36:26 +08:00
|
|
|
|
// 渲染两封示例邮件 HTML 到 .mail-preview/,供浏览器预览与 SMTP 试寄(不经过 Worker)
|
2026-10-04 08:45:40 +08:00
|
|
|
|
// 用法(在仓库根目录):
|
|
|
|
|
|
// npx tsc tools/preview-mail.ts src/lib/mail.ts --outDir .mail-build --module commonjs --target es2022 --moduleResolution node --skipLibCheck --esModuleInterop --noEmit false
|
|
|
|
|
|
// node .mail-build/tools/preview-mail.js
|
|
|
|
|
|
const { replyMailHtml, adminMailHtml, replyMailSubject, adminMailSubject } = require('../src/lib/mail');
|
|
|
|
|
|
|
|
|
|
|
|
const now = Date.now();
|
2026-10-05 07:36:26 +08:00
|
|
|
|
const parentMsg = {
|
2026-10-04 08:45:40 +08:00
|
|
|
|
id: 15630,
|
2026-10-05 07:36:26 +08:00
|
|
|
|
content: '终于恢复更新了啊,最近也在考虑要不要再次拥抱静态 🤔',
|
2026-10-04 08:45:40 +08:00
|
|
|
|
created_at: now - 3600_000,
|
|
|
|
|
|
page_key: '/comment.html',
|
|
|
|
|
|
};
|
|
|
|
|
|
const reply = {
|
|
|
|
|
|
id: 15631,
|
2026-10-05 07:36:26 +08:00
|
|
|
|
content:
|
|
|
|
|
|
'恢复了,今天有空,把服务全部迁移到 cloudflare 上了 ' +
|
|
|
|
|
|
'<img src="https://usj.cc/emotion/douyin/1.png" atk-emoticon="1">' +
|
|
|
|
|
|
' 欢迎回来常玩!<img src="https://usj.cc/emotion/bilibili/bq_1.png" atk-emoticon="2">',
|
2026-10-04 08:45:40 +08:00
|
|
|
|
created_at: now,
|
|
|
|
|
|
page_key: '/comment.html',
|
|
|
|
|
|
};
|
|
|
|
|
|
const newMsg = {
|
|
|
|
|
|
id: 15632,
|
2026-10-05 07:36:26 +08:00
|
|
|
|
content:
|
|
|
|
|
|
'测试留言:这个聊天气泡样式的邮件通知看起来真不错!' +
|
|
|
|
|
|
'<img src="https://usj.cc/emotion/weibo/wb1.png" atk-emoticon="33">' +
|
|
|
|
|
|
'<img src="https://usj.cc/emotion/twemoji/angry.png" atk-emoticon="1">' +
|
|
|
|
|
|
'<img src="https://pic.imgdb.cn/item/64ec38b4661c6c8e54c5acc2.jpg" alt="配图" title="配图">',
|
2026-10-04 08:45:40 +08:00
|
|
|
|
created_at: now,
|
|
|
|
|
|
page_key: '/comment.html',
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const site = { siteName: '优世界', siteUrl: 'https://usj.cc', pageTitle: '留言', pageUrl: 'https://usj.cc/comment.html' };
|
|
|
|
|
|
|
|
|
|
|
|
const replyHtml = replyMailHtml({
|
|
|
|
|
|
...site,
|
2026-10-05 07:36:26 +08:00
|
|
|
|
parentComment: parentMsg,
|
2026-10-04 08:45:40 +08:00
|
|
|
|
parentNick: '扳布',
|
|
|
|
|
|
parentEmail: 'banbu@example.com',
|
|
|
|
|
|
comment: reply,
|
|
|
|
|
|
commenterNick: '小赵',
|
|
|
|
|
|
commenterEmail: 'imql@qq.com',
|
|
|
|
|
|
toNick: '扳布',
|
|
|
|
|
|
});
|
|
|
|
|
|
const adminHtml = adminMailHtml({
|
|
|
|
|
|
...site,
|
|
|
|
|
|
comment: newMsg,
|
|
|
|
|
|
commenterNick: '测试访客',
|
|
|
|
|
|
commenterEmail: 'guest@example.com',
|
|
|
|
|
|
adminNick: '小赵',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
fs.mkdirSync(__dirname + '/.mail-preview', { recursive: true });
|
|
|
|
|
|
fs.writeFileSync(__dirname + '/.mail-preview/reply.html', replyHtml);
|
|
|
|
|
|
fs.writeFileSync(__dirname + '/.mail-preview/notice.html', adminHtml);
|
2026-10-05 07:36:26 +08:00
|
|
|
|
// 试寄用的主题也落盘,发送脚本直接读
|
|
|
|
|
|
fs.writeFileSync(__dirname + '/.mail-preview/reply.subject.txt', replyMailSubject({
|
|
|
|
|
|
...site, parentComment: parentMsg, parentNick: 'a', parentEmail: 'a@a.com',
|
|
|
|
|
|
comment: reply, commenterNick: '小赵', commenterEmail: 'b@b.com', toNick: '扳布',
|
|
|
|
|
|
}));
|
|
|
|
|
|
fs.writeFileSync(__dirname + '/.mail-preview/notice.subject.txt', adminMailSubject({ ...site, comment: newMsg, commenterNick: 'c', commenterEmail: 'c@c.com', adminNick: 'x' }));
|
2026-10-04 08:45:40 +08:00
|
|
|
|
console.log('SUBJECT reply :', replyMailSubject({
|
2026-10-05 07:36:26 +08:00
|
|
|
|
...site, parentComment: parentMsg, parentNick: 'a', parentEmail: 'a@a.com',
|
2026-10-04 08:45:40 +08:00
|
|
|
|
comment: reply, commenterNick: '小赵', commenterEmail: 'b@b.com', toNick: '扳布',
|
|
|
|
|
|
}));
|
|
|
|
|
|
console.log('SUBJECT notice:', adminMailSubject({ ...site, comment: newMsg, commenterNick: 'c', commenterEmail: 'c@c.com', adminNick: 'x' }));
|
|
|
|
|
|
console.log('OK');
|