From 920847245fa7d95e037709653b131400e2e6ab82 Mon Sep 17 00:00:00 2001 From: MovingEarth <40818895+MovingEarth@users.noreply.github.com> Date: Sun, 28 Nov 2021 20:45:07 +0100 Subject: [PATCH] Server: Do not set the SMTP auth option when user or password are not set (#5791) --- packages/server/src/services/EmailService.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/server/src/services/EmailService.ts b/packages/server/src/services/EmailService.ts index 443ce69023..d428b004f4 100644 --- a/packages/server/src/services/EmailService.ts +++ b/packages/server/src/services/EmailService.ts @@ -1,6 +1,7 @@ import Logger from '@joplin/lib/Logger'; import BaseService from './BaseService'; import Mail = require('nodemailer/lib/mailer'); +import SMTPTransport = require('nodemailer/lib/smtp-transport'); import { createTransport } from 'nodemailer'; import { Email, EmailSender } from '../services/database/types'; import { errorToString } from '../utils/errors'; @@ -24,16 +25,18 @@ export default class EmailService extends BaseService { if (!this.senderInfo(EmailSender.NoReply).email) { throw new Error('No-reply email must be set for email service to work (Set env variable MAILER_NOREPLY_EMAIL)'); } - - this.transport_ = createTransport({ + const options: SMTPTransport.Options = { host: this.config.mailer.host, port: this.config.mailer.port, secure: this.config.mailer.secure, - auth: { + }; + if (this.config.mailer.authUser || this.config.mailer.authPassword) { + options.auth = { user: this.config.mailer.authUser, pass: this.config.mailer.authPassword, - }, - }); + }; + } + this.transport_ = createTransport(options); await this.transport_.verify(); logger.info('Transporter is operational - service will be enabled');