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/mailer.ts | 31 +++++++ lib/mail/sendEmail.ts | 36 ++++++++ lib/mail/templates/admin-created.hbs | 78 ++++++++++++++++++ lib/mail/templates/admin-email-changed.hbs | 90 ++++++++++++++++++++ lib/mail/templates/otp.hbs | 77 +++++++++++++++++ lib/mail/templates/rfq-invite.hbs | 116 ++++++++++++++++++++++++++ lib/mail/templates/vendor-active.hbs | 51 ++++++++++++ lib/mail/templates/vendor-pq-comment.hbs | 128 +++++++++++++++++++++++++++++ lib/mail/templates/vendor-pq-status.hbs | 48 +++++++++++ 9 files changed, 655 insertions(+) create mode 100644 lib/mail/mailer.ts create mode 100644 lib/mail/sendEmail.ts create mode 100644 lib/mail/templates/admin-created.hbs create mode 100644 lib/mail/templates/admin-email-changed.hbs create mode 100644 lib/mail/templates/otp.hbs create mode 100644 lib/mail/templates/rfq-invite.hbs create mode 100644 lib/mail/templates/vendor-active.hbs create mode 100644 lib/mail/templates/vendor-pq-comment.hbs create mode 100644 lib/mail/templates/vendor-pq-status.hbs (limited to 'lib/mail') diff --git a/lib/mail/mailer.ts b/lib/mail/mailer.ts new file mode 100644 index 00000000..e0a90f1e --- /dev/null +++ b/lib/mail/mailer.ts @@ -0,0 +1,31 @@ +import nodemailer from 'nodemailer'; +import handlebars from 'handlebars'; +import fs from 'fs'; +import path from 'path'; +import i18next from 'i18next'; + +// Nodemailer Transporter 생성 +const transporter = nodemailer.createTransport({ + host: process.env.Email_Host, + port: 465, + secure: true, + auth: { + user: process.env.Email_User_Name, + pass: process.env.Email_Password, + }, +}); + +// Handlebars 템플릿 로더 함수 +function loadTemplate(templateName: string, data: Record) { + const templatePath = path.join(process.cwd(), 'lib', 'mail', 'templates', `${templateName}.hbs`); + const source = fs.readFileSync(templatePath, 'utf8'); + const template = handlebars.compile(source); + return template(data); +} + +handlebars.registerHelper('t', function(key: string, options: any) { + // options.hash에는 Handlebars에서 넘긴 named parameter들(location=location 등)이 들어있음 + return i18next.t(key, options.hash || {}); + }); + +export { transporter, loadTemplate }; \ No newline at end of file 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 + }); +} + diff --git a/lib/mail/templates/admin-created.hbs b/lib/mail/templates/admin-created.hbs new file mode 100644 index 00000000..7be7f15d --- /dev/null +++ b/lib/mail/templates/admin-created.hbs @@ -0,0 +1,78 @@ + + + + + {{t "adminCreated.title" lng=language}} + + + +
+ +
+ + +
+ +

{{t "adminCreated.title" lng=language}}

+ +

+ {{t "adminCreated.greeting" lng=language}}, {{name}}. +

+ +

+ {{t "adminCreated.body1" lng=language}} +

+ +

+ {{t "adminCreated.loginCTA" lng=language}} +

+ +

+ {{t "adminCreated.supportMsg" lng=language}} +

+ + +
+ + \ No newline at end of file diff --git a/lib/mail/templates/admin-email-changed.hbs b/lib/mail/templates/admin-email-changed.hbs new file mode 100644 index 00000000..7b8ca473 --- /dev/null +++ b/lib/mail/templates/admin-email-changed.hbs @@ -0,0 +1,90 @@ + + + + + {{t "adminEmailChanged.title" lng=language}} + + + +
+ +
+ + +
+ + +

{{t "adminEmailChanged.title" lng=language}}

+ + +

+ {{t "adminEmailChanged.greeting" lng=language}}, {{name}}. +

+ + +

+ {{t "adminEmailChanged.body.intro" lng=language}} +

+

+ {{t "adminEmailChanged.body.oldEmail" lng=language}}: {{oldEmail}}
+ {{t "adminEmailChanged.body.newEmail" lng=language}}: {{newEmail}} +

+ + +

+ + {{t "adminEmailChanged.loginCTA" lng=language}} + +

+ + +

+ {{t "adminEmailChanged.supportMsg" lng=language}} +

+ + + +
+ + \ No newline at end of file diff --git a/lib/mail/templates/otp.hbs b/lib/mail/templates/otp.hbs new file mode 100644 index 00000000..adeda416 --- /dev/null +++ b/lib/mail/templates/otp.hbs @@ -0,0 +1,77 @@ + + + + + + {{subject}} + + + +
+

{{t "verifyYourEmailTitle"}}

+

{{t "greeting"}}, {{name}}

+ +

+ {{t "receivedSignInAttempt" location=location}} +

+ +

+ {{t "enterCodeInstruction"}} +

+ +

{{otp}}

+ +

+ {{verificationUrl}} +

+ + + +
+ + \ No newline at end of file diff --git a/lib/mail/templates/rfq-invite.hbs b/lib/mail/templates/rfq-invite.hbs new file mode 100644 index 00000000..25bd96eb --- /dev/null +++ b/lib/mail/templates/rfq-invite.hbs @@ -0,0 +1,116 @@ + + + + + {{t "rfqInvite.title" lng=language}} #{{rfqCode}} + + + +
+ +
+ + +
+ + +

+ {{t "rfqInvite.heading" lng=language}} + #{{rfqCode}} +

+ + +

+ {{t "rfqInvite.greeting" lng=language}}, Vendor #{{vendorId}}. +

+ + +

+ {{t "rfqInvite.bodyIntro" lng=language}} +
+ {{t "rfqInvite.projectName" lng=language}}: {{projectName}}
+ {{t "rfqInvite.projectCode" lng=language}}: {{projectCode}}
+ {{t "rfqInvite.dueDate" lng=language}}: {{dueDate}}
+ {{t "rfqInvite.description" lng=language}}: {{description}} +

+ + +

+ {{t "rfqInvite.itemListTitle" lng=language}} +

+
    + {{#each items}} +
  • + {{this.itemCode}} + ({{this.quantity}} {{this.uom}}) + - {{this.description}} +
  • + {{/each}} +
+ + +

+ {{t "rfqInvite.moreDetail" lng=language}} +

+ + {{t "rfqInvite.viewButton" lng=language}} + + + +

+ {{t "rfqInvite.supportMsg" lng=language}} +

+ + + +
+ + \ No newline at end of file diff --git a/lib/mail/templates/vendor-active.hbs b/lib/mail/templates/vendor-active.hbs new file mode 100644 index 00000000..6458e2fb --- /dev/null +++ b/lib/mail/templates/vendor-active.hbs @@ -0,0 +1,51 @@ + + + + + 벤더 등록이 완료되었습니다 + + + +
+
+

벤더 등록이 완료되었습니다

+
+ +
+

{{vendorName}} 귀하,

+ +

축하합니다! 귀사의 벤더 등록이 완료되었으며 벤더 정보가 당사 시스템에 성공적으로 등록되었습니다.

+ +

귀사의 벤더 코드는 다음과 같습니다:

+
{{vendorCode}}
+ +

향후 모든 의사소통 및 거래 시 이 벤더 코드를 사용해 주십시오. 이제 벤더 포털에 접속하여 계정 관리, 발주서 확인 및 인보이스 제출을 할 수 있습니다.

+ +

+ 벤더 포털 접속 +

+ +

벤더 계정에 관한 질문이나 도움이 필요하시면 당사 벤더 관리팀에 문의해 주십시오.

+ +

파트너십에 감사드립니다.

+ +

감사합니다.
+ eVCP 팀

+
+ + +
+ + \ No newline at end of file diff --git a/lib/mail/templates/vendor-pq-comment.hbs b/lib/mail/templates/vendor-pq-comment.hbs new file mode 100644 index 00000000..b60deedc --- /dev/null +++ b/lib/mail/templates/vendor-pq-comment.hbs @@ -0,0 +1,128 @@ + + + + + + PQ Review Comments + + + +
+
+

PQ Review Comments

+
+ +
+

Dear {{name}} ({{vendorCode}}),

+ +

Thank you for submitting your PQ information. Our review team has completed the initial review and has requested some changes or additional information.

+ +

Action Required: Please log in to your account and update your PQ submission based on the comments below.

+ + {{#if hasGeneralComment}} +
+

General Comments:

+

{{generalComment}}

+
+ {{/if}} + +
+

Specific Item Comments ({{commentCount}}):

+ {{#each comments}} +
+
+ {{code}} + {{checkPoint}} +
+

{{text}}

+
+ {{/each}} +
+ +

Please review these comments and make the necessary updates to your PQ submission. Once you have made the requested changes, you can resubmit your PQ for further review.

+ + + +

If you have any questions or need assistance, please contact our support team.

+ +

Thank you for your cooperation.

+ +

Best regards,
+ PQ Review Team

+
+ + +
+ + \ No newline at end of file diff --git a/lib/mail/templates/vendor-pq-status.hbs b/lib/mail/templates/vendor-pq-status.hbs new file mode 100644 index 00000000..541a6137 --- /dev/null +++ b/lib/mail/templates/vendor-pq-status.hbs @@ -0,0 +1,48 @@ + + + + + + + + +
+ + + + + + + + + + +
+

Vendor PQ Status Update

+
+

Hello {{name}},

+

+ Your vendor status has been updated to + {{status}}. +

+

+ You can log in to see details and take further action: +
+ + Go to Portal + +

+

+ If you have any questions, feel free to contact us. +

+

Thank you,
+ The PQ Team +

+
+ + © 2023 MyCompany + +
+
+ + \ No newline at end of file -- cgit v1.2.3