import { Resend } from 'resend'; const resend = new Resend(process.env.RESEND_API_KEY); interface SendEmailParams { to: string; subject: string; html: string; } export async function sendEmail({ to, subject, html }: SendEmailParams) { try { console.log('准备发送邮件:', { to, subject, from: process.env.RESEND_FROM_EMAIL, apiKeyExists: !!process.env.RESEND_API_KEY }); if (!process.env.RESEND_API_KEY) { console.error('RESEND_API_KEY未设置'); return { success: false, error: 'RESEND_API_KEY未设置' }; } if (!process.env.RESEND_FROM_EMAIL) { console.error('RESEND_FROM_EMAIL未设置'); return { success: false, error: 'RESEND_FROM_EMAIL未设置' }; } const data = await resend.emails.send({ from: process.env.RESEND_FROM_EMAIL!, to, subject, html, }); console.log('邮件发送成功:', data); return { success: true, data }; } catch (error) { console.error('邮件发送失败详细信息:', { error: error instanceof Error ? error.message : error, stack: error instanceof Error ? error.stack : undefined, to, subject }); return { success: false, error }; } } export function generateVerificationEmailHtml(verificationUrl: string, locale: string = 'en') { const isZh = locale === 'zh'; return ` ${isZh ? '邮箱验证' : 'Email Verification'}

Aiartools

${isZh ? '邮箱验证' : 'Email Verification'}

${isZh ? '您好!' : 'Hello!'}

${isZh ? '感谢您注册Aiartools!请点击下面的按钮验证您的邮箱地址:' : 'Thank you for signing up for Aiartools! Please click the button below to verify your email address:'}

${isZh ? '验证邮箱' : 'Verify Email'}

${isZh ? '或者复制以下链接到浏览器中:' : 'Or copy and paste this link into your browser:'}

${verificationUrl}

${isZh ? '此链接将在24小时后过期。' : 'This link will expire in 24 hours.'}

${isZh ? '如果您没有注册Aiartools账户,请忽略此邮件。' : 'If you did not sign up for Aiartools, please ignore this email.'}

`; } export function generatePasswordResetEmailHtml(resetUrl: string, locale: string = 'zh'): string { const isZh = locale === 'zh'; return ` ${isZh ? 'Aiartools - 密码重置' : 'Aiartools - Password Reset'}

${isZh ? '密码重置请求' : 'Password Reset Request'}

${isZh ? '您好!' : 'Hello!'}

${isZh ? '我们收到了您的密码重置请求。点击下面的按钮来重置您的密码:' : 'We received a request to reset your password. Click the button below to reset your password:' }

${isZh ? '重置密码' : 'Reset Password'}

${isZh ? '重要提示:' : 'Important:'}

  • ${isZh ? '此链接将在24小时后过期' : 'This link will expire in 24 hours'}
  • ${isZh ? '如果您没有请求重置密码,请忽略此邮件' : 'If you did not request this password reset, please ignore this email'}
  • ${isZh ? '为了安全,请不要将此链接分享给他人' : 'For security reasons, do not share this link with others'}

${isZh ? '如果按钮无法点击,请复制以下链接到浏览器中打开:' : 'If the button doesn\'t work, copy and paste this link into your browser:' }

${resetUrl}

`; }