diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-03-26 00:37:41 +0000 |
| commit | e0dfb55c5457aec489fc084c4567e791b4c65eb1 (patch) | |
| tree | 68543a65d88f5afb3a0202925804103daa91bc6f /lib/mail/sendEmail.ts | |
3/25 까지의 대표님 작업사항
Diffstat (limited to 'lib/mail/sendEmail.ts')
| -rw-r--r-- | lib/mail/sendEmail.ts | 36 |
1 files changed, 36 insertions, 0 deletions
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<string, any>; // 템플릿에 주입할 데이터 + 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" <dujin.kim@dtsolution.co.kr>', + to, + subject, + html, + attachments + }); +} + |
