// 渲染两封示例邮件 HTML 到 .mail-preview/,供浏览器预览与 SMTP 试寄(不经过 Worker)
// 用法(在仓库根目录):
// 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();
const parentMsg = {
id: 15630,
content: '终于恢复更新了啊,最近也在考虑要不要再次拥抱静态 🤔',
created_at: now - 3600_000,
page_key: '/comment.html',
};
const reply = {
id: 15631,
content:
'恢复了,今天有空,把服务全部迁移到 cloudflare 上了 ' +
'
' +
' 欢迎回来常玩!
',
created_at: now,
page_key: '/comment.html',
};
const newMsg = {
id: 15632,
content:
'测试留言:这个聊天气泡样式的邮件通知看起来真不错!' +
'
' +
'
' +
'
',
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,
parentComment: parentMsg,
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);
// 试寄用的主题也落盘,发送脚本直接读
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' }));
console.log('SUBJECT reply :', replyMailSubject({
...site, parentComment: parentMsg, parentNick: 'a', parentEmail: 'a@a.com',
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');