import * as nodemailer from 'nodemailer' /** * 이메일 발송 유틸리티 */ let transporter: nodemailer.Transporter | null = null function getTransporter() { if (transporter) return transporter const host = process.env.SMTP_HOST || 'smtp.gmail.com' const port = parseInt(process.env.SMTP_PORT || '587') const user = process.env.SMTP_USER || '' const pass = process.env.SMTP_PASS || '' if (!user || !pass) { console.warn('SMTP credentials not configured') return null } transporter = nodemailer.createTransport({ host, port, secure: port === 465, auth: { user, pass } }) return transporter } interface EmailOptions { to: string subject: string html: string text?: string } export async function sendEmail(options: EmailOptions): Promise { const t = getTransporter() if (!t) { console.error('Email transporter not configured') return false } const from = process.env.SMTP_FROM || process.env.SMTP_USER || 'noreply@example.com' try { await t.sendMail({ from, to: options.to, subject: options.subject, html: options.html, text: options.text }) return true } catch (e) { console.error('Email send error:', e) return false } } /** * 임시 비밀번호 이메일 발송 */ export async function sendTempPasswordEmail( toEmail: string, employeeName: string, tempPassword: string ): Promise { const subject = '[업무관리프로그램] 임시 비밀번호 발급' const html = `

임시 비밀번호 발급

안녕하세요, ${employeeName}님.

요청하신 임시 비밀번호가 발급되었습니다.

임시 비밀번호:

${tempPassword}

※ 로그인 후 반드시 비밀번호를 변경해 주세요.
※ 본인이 요청하지 않은 경우, 이 메일을 무시하세요.


업무관리프로그램

` const text = `임시 비밀번호: ${tempPassword}\n\n로그인 후 비밀번호를 변경해 주세요.` return sendEmail({ to: toEmail, subject, html, text }) }