cursor-init/quick-email-test.ts
HeXiaoLong:Suanier c6a3ad5332 fix: 修复QQ邮箱From字段格式问题
- 修正From字段配置,确保邮箱地址与SMTP认证用户一致

- 添加fromName支持,支持自定义发件人显示名称

- 改进From字段格式化,符合RFC5322标准

- 添加配置验证,防止空邮箱地址错误

- 创建QQ邮箱配置指南和测试demo

解决550 From header错误,完善邮件服务
2025-07-04 18:42:20 +08:00

59 lines
1.8 KiB
TypeScript

/**
* 快速邮件测试脚本
* 运行方式: bun run quick-email-test.ts your@email.com
*/
import {
initializeEmailService,
sendEmail,
closeEmailService
} from './src/plugins/email/email.service';
async function quickTest() {
const testEmail = process.argv[2];
if (!testEmail) {
console.log('❌ 请提供邮箱地址');
console.log('💡 使用方法: bun run quick-email-test.ts your@email.com');
return;
}
console.log('📧 快速邮件测试开始...');
console.log(`🎯 目标邮箱: ${testEmail}`);
try {
// 初始化邮件服务
console.log('🚀 初始化邮件服务...');
await initializeEmailService();
console.log('✅ 初始化成功');
// 发送测试邮件
console.log('📮 发送测试邮件...');
const result = await sendEmail({
to: testEmail,
subject: '🧪 邮件服务测试',
html: `
<h2>🎉 邮件测试成功!</h2>
<p>如果您收到这封邮件,说明邮件服务配置正确。</p>
<p><small>发送时间: ${new Date().toLocaleString('zh-CN')}</small></p>
`
});
if (result.success) {
console.log('✅ 邮件发送成功!');
console.log(`📮 消息ID: ${result.messageId}`);
console.log('📬 请检查您的邮箱收件箱(包括垃圾邮件文件夹)');
} else {
console.log('❌ 邮件发送失败');
console.log(`💥 错误: ${result.error}`);
}
} catch (error) {
console.log('💥 执行失败:', error);
} finally {
await closeEmailService();
console.log('🔚 服务已关闭');
}
}
quickTest();