From 90f79a7a691943a496f67f01c1e493256070e4de Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 7 Jul 2025 01:44:45 +0000 Subject: (대표님) 변경사항 20250707 10시 43분 - unstaged 변경사항 추가 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mail/sendEmail.ts | 53 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'lib/mail/sendEmail.ts') diff --git a/lib/mail/sendEmail.ts b/lib/mail/sendEmail.ts index 97617e7a..3f88cb04 100644 --- a/lib/mail/sendEmail.ts +++ b/lib/mail/sendEmail.ts @@ -17,29 +17,42 @@ interface SendEmailOptions { }[] } -export async function sendEmail({ - to, - subject, - template, - context, +export async function sendEmail({ + to, + subject, + template, + context, cc, // cc 매개변수 추가 attachments = [] }: SendEmailOptions) { - const { t, i18n } = await useTranslation(context.language ?? "en", "translation"); + try { + // i18n 설정 + const { t, i18n } = await useTranslation(context.language ?? "en", "translation"); + + // t 헬퍼만 동적으로 등록 (이미 mailer.ts에서 기본 등록되어 있지만, 언어별로 다시 등록) + handlebars.registerHelper("t", function (key: string, options: any) { + // 여기서 i18n은 로컬 인스턴스 + return i18n.t(key, options.hash || {}); + }); - handlebars.registerHelper("t", function (key: string, options: any) { - // 여기서 i18n은 로컬 인스턴스 - return i18n.t(key, options.hash || {}); - }); + // 템플릿 컴파일 및 HTML 생성 + const html = loadTemplate(template, context); - const html = loadTemplate(template, context); + // 이메일 발송 + const result = await transporter.sendMail({ + from: `"${process.env.Email_From_Name}" <${process.env.Email_From_Address}>`, + to, + cc, // cc 필드 추가 + subject, + html, + attachments + }); - await transporter.sendMail({ - from: `"${process.env.Email_From_Name}" <${process.env.Email_From_Address}>`, - to, - cc, // cc 필드 추가 - subject, - html, - attachments - }); -} + console.log(`이메일 발송 성공: ${to}`, result.messageId); + return result; + + } catch (error) { + console.error(`이메일 발송 실패: ${to}`, error); + throw error; + } +} \ No newline at end of file -- cgit v1.2.3