From 6772d0c964558c41bef06b4a773057acfd6076af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahlstr=C3=B6m=20Kalle?= Date: Wed, 24 Jan 2024 01:13:02 +0200 Subject: [PATCH] fix mailing system --- cms/src/api/email/services/email.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cms/src/api/email/services/email.ts b/cms/src/api/email/services/email.ts index 32dd52a..ac5891b 100644 --- a/cms/src/api/email/services/email.ts +++ b/cms/src/api/email/services/email.ts @@ -1,30 +1,31 @@ /** * email service. */ -import NodeMailer from 'nodemailer'; -import { factories } from '@strapi/strapi'; +import { createTransport } from "nodemailer"; +import { factories } from "@strapi/strapi"; const smtpUser = process.env.SMTP_USER; const smtpPassword = process.env.SMTP_PASSWORD; - -const transporter = NodeMailer.createTransport({ - service: 'gmail', +const smtpHost = process.env.SMTP_HOST || "smtp.gmail.com."; +const stmpTLS = process.env.SMTP_TLS === "true"; +const transporter = createTransport({ + host: smtpHost, + secure: stmpTLS, auth: { user: smtpUser, - pass: smtpPassword + pass: smtpPassword, }, - pool: true + pool: true, }); transporter .verify() - .then(() =>console.log('Mailer setup succesfully')) - .catch((error) => console.error('Mailer error', error)) + .then(() => console.log("Mailer setup succesfully")) + .catch((error) => console.error("Mailer error", error)); -export default factories.createCoreService('api::email.email',{ - create: async(options: Record) => { +export default factories.createCoreService("api::email.email", { + create: async (options: Record) => { await transporter.sendMail(options); return null; }, -} -); +});