diff --git a/src/modules/configuration/mail/domain/helpers/send-email.helper.ts b/src/modules/configuration/mail/domain/helpers/send-email.helper.ts index 87dd1ee..c242887 100644 --- a/src/modules/configuration/mail/domain/helpers/send-email.helper.ts +++ b/src/modules/configuration/mail/domain/helpers/send-email.helper.ts @@ -16,35 +16,39 @@ export async function sendEmail(receivers, subject) { let templateName = 'payment-confirmation-bank'; for (const receiver of receivers) { - if (receiver.payment_type == TransactionPaymentType.MIDTRANS) - templateName = 'payment-confirmation-midtrans'; + try { + if (receiver.payment_type == TransactionPaymentType.MIDTRANS) + templateName = 'payment-confirmation-midtrans'; - let templatePath = path.resolve( - __dirname, - `../email-template/${templateName}.html`, - ); - templatePath = templatePath.replace(/dist/g, 'src'); - const templateSource = fs.readFileSync(templatePath, 'utf8'); + let templatePath = path.resolve( + __dirname, + `../email-template/${ templateName }.html`, + ); + templatePath = templatePath.replace(/dist/g, 'src'); + const templateSource = fs.readFileSync(templatePath, 'utf8'); - const template = handlebars.compile(templateSource); - const htmlToSend = template(receiver); + const template = handlebars.compile(templateSource); + const htmlToSend = template(receiver); - const emailContext = { - from: 'no-reply@eigen.co.id', - to: receiver.email, - subject: subject, - html: htmlToSend, - attachDataUrls: true, - }; + const emailContext = { + from: 'no-reply@eigen.co.id', + to: receiver.email, + subject: subject, + html: htmlToSend, + attachDataUrls: true, + }; - await new Promise((f) => setTimeout(f, 2000)); + await new Promise((f) => setTimeout(f, 2000)); - smtpTransport.sendMail(emailContext, function (err, data) { - if (err) { - console.log(`Error occurs on send to ${receiver.email}`); - } else { - console.log(`Email sent to ${receiver.email}`); - } - }); + smtpTransport.sendMail(emailContext, function (err, data) { + if (err) { + console.log(err, `Error occurs on send to ${ receiver.email }`); + } else { + console.log(`Email sent to ${ receiver.email }`); + } + }); + } catch (error) { + console.log(error, `Error occurs on send to ${ receiver.email }`) + } } }