From e0dfb55c5457aec489fc084c4567e791b4c65eb1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 26 Mar 2025 00:37:41 +0000 Subject: 3/25 까지의 대표님 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mail/sendEmail.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/mail/sendEmail.ts (limited to 'lib/mail/sendEmail.ts') diff --git a/lib/mail/sendEmail.ts b/lib/mail/sendEmail.ts new file mode 100644 index 00000000..48cc1fbc --- /dev/null +++ b/lib/mail/sendEmail.ts @@ -0,0 +1,36 @@ +import { useTranslation } from '@/i18n'; +import { transporter, loadTemplate } from './mailer'; +import handlebars from 'handlebars'; + +interface SendEmailOptions { + to: string; + subject: string; + template: string; // 템플릿 파일명(확장자 제외) + context: Record; // 템플릿에 주입할 데이터 + attachments?: { // NodeMailer "Attachment" 타입 + filename?: string + path?: string + content?: Buffer | string + // ... + }[] +} + +export async function sendEmail({ to, subject, template, context, attachments = []}: SendEmailOptions) { + const { t, i18n } = await useTranslation(context.language ?? "en", "translation"); + + handlebars.registerHelper("t", function (key: string, options: any) { + // 여기서 i18n은 로컬 인스턴스 + return i18n.t(key, options.hash || {}); + }); + + const html = loadTemplate(template, context); + + await transporter.sendMail({ + from: 'EVCP" ', + to, + subject, + html, + attachments + }); +} + -- cgit v1.2.3