1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Server: Do not set the SMTP auth option when user or password are not set (#5791)

This commit is contained in:
MovingEarth 2021-11-28 20:45:07 +01:00 committed by GitHub
parent 605f12552e
commit 920847245f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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');