From 4d32f1e00248bc54c9acec0be626d1286645e2ed Mon Sep 17 00:00:00 2001 From: Ravinou Date: Sun, 5 Jan 2025 11:37:57 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20allow=20smtp=20settings?= =?UTF-8?q?=20without=20credentials=20#364?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helpers/functions/nodemailerSMTP.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/helpers/functions/nodemailerSMTP.js b/helpers/functions/nodemailerSMTP.js index 683951a..20a38a1 100644 --- a/helpers/functions/nodemailerSMTP.js +++ b/helpers/functions/nodemailerSMTP.js @@ -1,18 +1,26 @@ -//Lib import nodemailer from 'nodemailer'; export default function nodemailerSMTP() { - const transporter = nodemailer.createTransport({ + const config = { port: parseInt(process.env.MAIL_SMTP_PORT, 10), host: process.env.MAIL_SMTP_HOST, - auth: { - user: process.env.MAIL_SMTP_LOGIN || '', - pass: process.env.MAIL_SMTP_PWD || '', - }, tls: { // false value allow self-signed or invalid TLS certificate rejectUnauthorized: process.env.MAIL_REJECT_SELFSIGNED_TLS === 'false' ? false : true, }, - }); + }; + + const smtpLogin = process.env.MAIL_SMTP_LOGIN || ''; + const smtpPwd = process.env.MAIL_SMTP_PWD || ''; + + // Some SMTP servers doesn't require authentication #364 + if (smtpLogin) { + config.auth = { + user: smtpLogin, + pass: smtpPwd, + }; + } + + const transporter = nodemailer.createTransport(config); return transporter; }