Skip to content

Commit

Permalink
fix mailing system
Browse files Browse the repository at this point in the history
  • Loading branch information
kahlstrm committed Jan 23, 2024
1 parent 3d37f65 commit 6772d0c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions cms/src/api/email/services/email.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>) => {
export default factories.createCoreService("api::email.email", {
create: async (options: Record<string, unknown>) => {
await transporter.sendMail(options);
return null;
},
}
);
});

0 comments on commit 6772d0c

Please sign in to comment.