1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Server: Resolves #5222: Fixed handling of mailer security settings, and changed env variable name MAILER_SECURE => MAILER_SECURITY, and default port 587 => 465 (Breaking change)

This commit is contained in:
Laurent Cozic 2022-01-09 11:13:48 +00:00
parent f6ed5eb064
commit df14ffdee2
4 changed files with 20 additions and 6 deletions

View File

@ -66,7 +66,7 @@ function mailerConfigFromEnv(env: EnvVariables): MailerConfig {
enabled: env.MAILER_ENABLED,
host: env.MAILER_HOST,
port: env.MAILER_PORT,
secure: env.MAILER_SECURE,
security: env.MAILER_SECURITY,
authUser: env.MAILER_AUTH_USER,
authPassword: env.MAILER_AUTH_PASSWORD,
noReplyName: env.MAILER_NOREPLY_NAME,

View File

@ -3,6 +3,12 @@
// The env variables can be of type string, integer or boolean. When the type is
// boolean, set the variable to "0" or "1" in your env file.
export enum MailerSecurity {
None = 'none',
Tls = 'tls',
Starttls = 'starttls',
}
const defaultEnvValues: EnvVariables = {
// ==================================================
// General config
@ -66,8 +72,8 @@ const defaultEnvValues: EnvVariables = {
MAILER_ENABLED: false,
MAILER_HOST: '',
MAILER_PORT: 587,
MAILER_SECURE: true,
MAILER_PORT: 465,
MAILER_SECURITY: MailerSecurity.Tls,
MAILER_AUTH_USER: '',
MAILER_AUTH_PASSWORD: '',
MAILER_NOREPLY_NAME: '',
@ -120,7 +126,7 @@ export interface EnvVariables {
MAILER_ENABLED: boolean;
MAILER_HOST: string;
MAILER_PORT: number;
MAILER_SECURE: boolean;
MAILER_SECURITY: MailerSecurity;
MAILER_AUTH_USER: string;
MAILER_AUTH_PASSWORD: string;
MAILER_NOREPLY_NAME: string;

View File

@ -7,6 +7,7 @@ import { Email, EmailSender } from '../services/database/types';
import { errorToString } from '../utils/errors';
import EmailModel from '../models/EmailModel';
import { markdownBodyToHtml, markdownBodyToPlainText } from './email/utils';
import { MailerSecurity } from '../env';
const logger = Logger.create('EmailService');
@ -25,10 +26,16 @@ 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)');
}
// NodeMailer's TLS options are weird:
// https://nodemailer.com/smtp/#tls-options
const options: SMTPTransport.Options = {
host: this.config.mailer.host,
port: this.config.mailer.port,
secure: this.config.mailer.secure,
secure: this.config.mailer.security === MailerSecurity.Tls,
ignoreTLS: this.config.mailer.security === MailerSecurity.None,
requireTLS: this.config.mailer.security === MailerSecurity.Starttls,
};
if (this.config.mailer.authUser || this.config.mailer.authPassword) {
options.auth = {

View File

@ -7,6 +7,7 @@ import { Account } from '../models/UserModel';
import { Services } from '../services/types';
import { Routers } from './routeUtils';
import { DbConnection } from '../db';
import { MailerSecurity } from '../env';
export enum Env {
Dev = 'dev',
@ -74,7 +75,7 @@ export interface MailerConfig {
enabled: boolean;
host: string;
port: number;
secure: boolean;
security: MailerSecurity;
authUser: string;
authPassword: string;
noReplyName: string;