-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
403 lines (352 loc) · 16.9 KB
/
index.html
File metadata and controls
403 lines (352 loc) · 16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Turbo Mail Sender — 轻色单栏</title>
<!-- Tailwind + Inter -->
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap" rel="stylesheet">
<!-- Quill -->
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<!-- Animations -->
<style>
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px);} to { opacity:1; transform: translateY(0); } }
.log-entry { opacity:0; transform:translateY(6px); animation: fadeInUp 420ms ease forwards; }
.btn-primary { transition: transform 160ms ease, box-shadow 160ms ease; }
.btn-primary:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(99,102,241,0.15); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.stat .num { transition: transform 220ms cubic-bezier(.2,.9,.3,1); }
.stat.pulse .num { transform: scale(1.08); }
@keyframes shimmer { 0% { background-position: -200px 0 } 100% { background-position: 200px 0 } }
.progress-shimmer { background-image: linear-gradient(90deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.18) 50%, rgba(255,255,255,0.08) 100%); background-size: 400px 100%; animation: shimmer 2.5s linear infinite; }
</style>
</head>
<body class="antialiased bg-gray-50 text-gray-800" style="font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;">
<div class="max-w-5xl mx-auto px-4 py-6">
<!-- HEADER: Minimal, clean -->
<header class="flex items-center justify-between mb-8">
<div class="flex items-center space-x-3">
<div class="w-11 h-11 rounded-lg bg-gradient-to-br from-indigo-600 to-blue-500 flex items-center justify-center text-white font-bold text-lg shadow-md">TM</div>
<div>
<h1 class="text-xl font-extrabold">Turbo Mail Sender</h1>
<p class="text-xs text-gray-500">批量邮件群发工具</p>
</div>
</div>
<div class="text-right">
<span id="connectionStatus" class="inline-flex items-center px-3 py-1 rounded-full bg-green-100 text-green-700 text-xs font-semibold">🟢 已连接</span>
<p class="text-xs text-gray-400 mt-1">本地服务</p>
</div>
</header>
<!-- SECTION 1: SMTP 配置 (简洁) -->
<section class="bg-white rounded-xl shadow-sm p-6 mb-5">
<div class="flex justify-between items-center mb-4">
<h2 class="text-sm font-bold text-gray-800 uppercase">STEP 1: 发件人配置</h2>
<span class="text-xs text-gray-400">SMTP</span>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
<input id="smtpHost" type="text" value="__SMTP_HOST__" placeholder="smtp.qq.com" class="border rounded-lg p-2 text-sm bg-white focus:ring-2 focus:ring-indigo-500 focus:outline-none">
<input id="smtpPort" type="number" value="__SMTP_PORT__" placeholder="465" class="border rounded-lg p-2 text-sm bg-white focus:ring-2 focus:ring-indigo-500 focus:outline-none">
<input id="senderEmail" type="email" value="__SENDER_EMAIL__" placeholder="you@example.com" class="border rounded-lg p-2 text-sm bg-white focus:ring-2 focus:ring-indigo-500 focus:outline-none">
<input id="senderPass" type="password" placeholder="授权码" class="border rounded-lg p-2 text-sm bg-white focus:ring-2 focus:ring-indigo-500 focus:outline-none">
</div>
</section>
<!-- SECTION 2: 邮件内容 (全宽) -->
<section class="bg-white rounded-xl shadow-sm p-6 mb-5">
<h2 class="text-sm font-bold text-gray-800 uppercase mb-4">STEP 2: 邮件内容</h2>
<input id="mailSubject" type="text" value="__MAIL_SUBJECT__" placeholder="邮件主题" class="w-full border rounded-lg p-2 text-sm bg-white mb-3 focus:ring-2 focus:ring-indigo-500 focus:outline-none">
<div id="ssrHtmlContent" style="display:none">__MAIL_CONTENT__</div>
<div id="editor-container" class="rounded-lg border bg-white" style="min-height:200px;"></div>
</section>
<!-- SECTION 3: 收件人 + 策略 + 监控 (水平三列布局) -->
<div class="grid grid-cols-1 lg:grid-cols-12 gap-5 mb-6">
<!-- 左:收件人列表 (lg:col-span-7) -->
<div class="lg:col-span-7">
<section class="bg-white rounded-xl shadow-sm p-6 h-full flex flex-col">
<div class="flex justify-between items-center mb-3">
<h2 class="text-sm font-bold text-gray-800 uppercase">STEP 3: 收件人</h2>
<span id="recipientCount" class="text-xs text-gray-500">0 人</span>
</div>
<textarea id="recipientList" rows="10" placeholder="zhangsan@example.com lisi@example.com 或粘贴邮箱列表" class="flex-1 border rounded-lg p-3 text-sm bg-white resize-none focus:ring-2 focus:ring-indigo-500 focus:outline-none mb-3"></textarea>
<!-- 按钮组:分开放置 -->
<div class="flex gap-2">
<input id="csvInput" type="file" accept=".csv,.txt" class="hidden" onchange="handleCsv(this)">
<button onclick="document.getElementById('csvInput').click()" class="px-4 py-2 rounded-lg border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 transition">
📂 导入 CSV
</button>
<button id="sendBtn" onclick="startBatchSend()" class="flex-1 px-6 py-3 rounded-lg bg-indigo-600 text-white font-bold text-center btn-primary">
🚀 START MISSION
</button>
</div>
</section>
</div>
<!-- 右:策略 + 监控 (lg:col-span-5) 竖排 -->
<div class="lg:col-span-5 flex flex-col gap-5">
<!-- 策略配置 (上半部分) -->
<section class="bg-white rounded-xl shadow-sm p-6">
<h3 class="text-sm font-bold text-gray-800 uppercase mb-3">发送策略</h3>
<div class="space-y-2">
<div>
<label class="text-xs text-gray-600 font-medium">单封延迟 (ms)</label>
<input id="cfgDelay" type="number" value="1000" class="w-full border rounded-lg p-2 text-sm bg-white focus:ring-2 focus:ring-indigo-500 focus:outline-none">
</div>
<div>
<label class="text-xs text-gray-600 font-medium">最大重试次数</label>
<input id="cfgMaxRetries" type="number" value="3" class="w-full border rounded-lg p-2 text-sm bg-white focus:ring-2 focus:ring-indigo-500 focus:outline-none">
</div>
</div>
</section>
<!-- 运行监控 (下半部分,增大) -->
<section class="bg-white rounded-xl shadow-sm p-6 flex-1">
<h3 class="text-sm font-bold text-gray-800 uppercase mb-3">运行监控</h3>
<!-- 进度条 -->
<div class="mb-3">
<div class="flex justify-between items-center text-xs text-gray-600 mb-1">
<span>Progress</span>
<span id="progressPercent" class="font-mono font-bold">0%</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-3 overflow-hidden">
<div id="progressBar" class="h-3 bg-gradient-to-r from-indigo-500 to-indigo-600 rounded-full transition-all" style="width:0%"></div>
</div>
</div>
<!-- 统计数字 -->
<div class="grid grid-cols-3 gap-2 mb-3">
<div class="stat bg-gray-50 rounded-lg p-3 text-center">
<div class="text-xs text-gray-600 font-medium">Queue</div>
<div id="statQueue" class="num font-mono font-bold text-xl text-gray-800">0</div>
</div>
<div class="stat bg-gray-50 rounded-lg p-3 text-center">
<div class="text-xs text-gray-600 font-medium">Sending</div>
<div id="statRunning" class="num font-mono font-bold text-xl text-blue-600">0</div>
</div>
<div class="stat bg-gray-50 rounded-lg p-3 text-center">
<div class="text-xs text-gray-600 font-medium">Done</div>
<div id="statDone" class="num font-mono font-bold text-xl text-green-600">0</div>
</div>
</div>
<!-- 日志窗 -->
<div id="logBox" class="h-32 overflow-auto border rounded-lg p-2 bg-white text-xs text-gray-700 space-y-1 mb-3">
<div class="text-gray-500">> System ready.</div>
</div>
<!-- 导出按钮 -->
<button onclick="downloadResults()" class="w-full px-4 py-2 rounded-lg border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 transition">
📥 导出结果
</button>
</section>
</div>
</div>
<footer class="text-center text-xs text-gray-500 py-4">
部署于本地 · 请勿滥用邮箱服务
</footer>
</div>
<!-- Quill -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<!-- JS: 保持所有现有逻辑不变 -->
<script>
// === 全局配置键 ===
const CONFIG_KEY = 'turbo_mailer_config_v2';
// === 1. 初始化 Quill 编辑器 ===
const quill = new Quill('#editor-container', {
theme: 'snow',
placeholder: '在此撰写邮件正文...',
modules: { toolbar: [['bold', 'italic', 'underline', 'strike'], [{ 'list': 'ordered'}, { 'list': 'bullet' }], [{ 'header': [1, 2, 3, false] }], ['link', 'clean']] }
});
// === 2. 智能数据加载 (SSR + LocalStorage) ===
window.addEventListener('DOMContentLoaded', () => {
// A. 尝试从 SSR 隐藏域加载 HTML 内容
const ssrHtmlContainer = document.getElementById('ssrHtmlContent');
if (ssrHtmlContainer) {
const ssrHtml = ssrHtmlContainer.innerHTML;
if (ssrHtml && ssrHtml !== '__MAIL_CONTENT__' && ssrHtml.trim() !== '') {
quill.root.innerHTML = ssrHtml;
}
}
// B. 处理 Input 占位符 & 缓存回填 (修复版)
const cachedConfig = JSON.parse(localStorage.getItem(CONFIG_KEY) || '{}');
// 配置字段映射(id -> 缓存键、默认值)
// 注:mailSubject 不再被缓存,发送完成后会清空
const fieldConfigs = {
smtpHost: { cacheKey: 'smtpHost', defaultVal: 'smtp.qq.com' },
smtpPort: { cacheKey: 'smtpPort', defaultVal: '465' },
senderEmail: { cacheKey: 'senderEmail', defaultVal: '' }
};
// 统一处理所有字段
Object.entries(fieldConfigs).forEach(([id, config]) => {
const el = document.getElementById(id);
if (!el) return;
const currentVal = el.value || '';
const isPlaceholder = currentVal.startsWith('__') && currentVal.endsWith('__');
const cachedVal = cachedConfig[config.cacheKey];
// 优先级:缓存 > SSR 已替换值 > 默认值
if (cachedVal) {
// 优先使用缓存
el.value = cachedVal;
} else if (!isPlaceholder && currentVal) {
// SSR 已替换且无缓存,保留该值
el.value = currentVal;
} else {
// 使用默认值
el.value = config.defaultVal;
}
});
// mailSubject 特殊处理:只从 SSR 注入,不从缓存恢复
const subjectEl = document.getElementById('mailSubject');
if (subjectEl && subjectEl.value.startsWith('__') && subjectEl.value.endsWith('__')) {
subjectEl.value = ''; // 清空占位符
}
// 特殊处理:密码字段(不在占位符中,纯缓存)
if (cachedConfig.senderPass) {
const passEl = document.getElementById('senderPass');
if (passEl) passEl.value = cachedConfig.senderPass;
}
// health check
fetch('/queue-status').then(r => {
if(r.ok) document.getElementById('connectionStatus').innerText = "🟢 已连接";
else document.getElementById('connectionStatus').innerText = "🔴 异常";
}).catch(() => {
document.getElementById('connectionStatus').innerText = "🔴 错误";
});
});
// === 3. 收件人处理 ===
const recipientListEl = document.getElementById('recipientList');
if (recipientListEl) recipientListEl.addEventListener('input', updateCount);
function updateCount() {
const text = recipientListEl.value || '';
const emails = text.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/gi) || [];
document.getElementById('recipientCount').innerText = `${emails.length} 人`;
return emails;
}
function handleCsv(input) {
const file = input.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
const text = e.target.result;
const emails = text.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/gi);
if (emails) {
const unique = [...new Set(emails)];
recipientListEl.value = unique.join('\n');
updateCount();
addLog(`已导入 ${unique.length} 个邮箱`, 'cmd');
} else {
alert('未找到有效邮箱');
}
};
reader.readAsText(file);
input.value = '';
}
// === 新增:清空发送内容 ===
function clearSendContent() {
recipientListEl.value = '';
document.getElementById('mailSubject').value = ''; // 清空邮件主题
quill.setText(''); // 清空 Quill 编辑器
updateCount();
addLog('✨ 已清空邮件内容和收件人列表', 'info');
}
// === 4. 发送逻辑 (核心) ===
let monitorTimer = null;
let initialTotal = 0;
async function startBatchSend() {
const host = document.getElementById('smtpHost').value.trim();
const port = document.getElementById('smtpPort').value.trim();
const user = document.getElementById('senderEmail').value.trim();
const pass = document.getElementById('senderPass').value.trim();
const subject = document.getElementById('mailSubject').value.trim();
const html = quill.root.innerHTML;
const configDelay = parseInt(document.getElementById('cfgDelay').value) || 1000;
const configRetries = parseInt(document.getElementById('cfgMaxRetries').value) || 3;
if (!host || !port || !user || !pass || !subject) return alert('请补全所有配置项');
const emails = updateCount();
const uniqueEmails = [...new Set(emails)];
if (uniqueEmails.length === 0) return alert('收件人列表为空');
// 缓存发件人信息:只保存 SMTP 配置,不保存邮件主题(一次性)
localStorage.setItem(CONFIG_KEY, JSON.stringify({
smtpHost: host, smtpPort: port, senderEmail: user, senderPass: pass
}));
const btn = document.getElementById('sendBtn');
btn.disabled = true;
btn.innerHTML = `<span class="inline-block animate-spin mr-2">↻</span> 提交中...`;
addLog(`正在提交 ${uniqueEmails.length} 个任务...`, 'info');
try {
const res = await fetch('/send-mail-batch', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
host, port, user, pass, recipients: uniqueEmails, subject, html,
clientConfig: { perSendDelay: configDelay, maxRetries: configRetries }
})
});
const data = await res.json();
if (data.success) {
initialTotal = uniqueEmails.length;
addLog(`✅ 成功入队 ${data.total} 个任务`, 'success');
btn.innerHTML = `正在发送... (0/${initialTotal})`;
if (!monitorTimer) monitorProgress();
} else {
throw new Error(data.message || '提交失败');
}
} catch (err) {
addLog(`提交失败: ${err.message}`, 'error');
btn.disabled = false;
btn.innerHTML = '🚀 START MISSION';
}
}
// === 5. 进度监控 ===
function monitorProgress() {
monitorTimer = setInterval(async () => {
try {
const res = await fetch('/queue-status');
const data = await res.json();
if (data.success) {
const { queueLength, running, totalProcessed } = data;
updateStat('statQueue', queueLength);
updateStat('statRunning', running);
updateStat('statDone', totalProcessed);
let p = initialTotal > 0 ? Math.round((totalProcessed / initialTotal) * 100) : 0;
if (p > 100 && queueLength > 0) p = 99;
if (queueLength === 0 && running === 0) p = 100;
document.getElementById('progressBar').style.width = p + '%';
document.getElementById('progressPercent').innerText = p + '%';
const btn = document.getElementById('sendBtn');
if (p < 100) btn.innerHTML = `正在发送... (${totalProcessed}/${initialTotal})`;
// 发送完成:清空内容、重置按钮、停止轮询
if (queueLength === 0 && running === 0 && totalProcessed >= initialTotal && initialTotal > 0) {
clearInterval(monitorTimer);
monitorTimer = null;
addLog('🎉 所有任务处理完毕', 'success');
clearSendContent(); // 清空邮件内容和收件人列表
btn.disabled = false;
btn.innerHTML = '🚀 START MISSION';
}
}
} catch (e) {
console.error("Poll error", e);
}
}, 1500);
}
function addLog(msg, type) {
const box = document.getElementById('logBox');
const colors = { 'info': '#3b82f6', 'success':'#10b981','error':'#ef4444','cmd':'#7c3aed' };
const time = new Date().toLocaleTimeString('en-US', {hour12:false});
const div = document.createElement('div');
div.className = 'log-entry';
div.style.color = colors[type] || '#3b82f6';
div.innerHTML = `<span style="opacity:.5">[${time}]</span> ${msg}`;
box.appendChild(div);
box.scrollTop = box.scrollHeight;
if (box.children.length > 500) box.removeChild(box.firstChild);
}
function updateStat(id, value) {
const el = document.getElementById(id);
if (!el) return;
el.innerText = value;
const parent = el.parentElement;
if (parent) {
parent.classList.add('pulse');
setTimeout(()=> parent.classList.remove('pulse'), 360);
}
}
function downloadResults() { window.open('/results', '_blank'); }
</script>
</body>
</html>