summaryrefslogtreecommitdiff
path: root/lib/mail/sendEmail.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mail/sendEmail.ts')
-rw-r--r--lib/mail/sendEmail.ts53
1 files changed, 33 insertions, 20 deletions
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