From db2c381c005269557018b560a04abd0f59dfc7aa Mon Sep 17 00:00:00 2001 From: Julen Landa Alustiza Date: Thu, 30 Mar 2017 19:13:57 +0200 Subject: Add TLS toggle option to smtp configuration --- models/settings.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'models/settings.js') diff --git a/models/settings.js b/models/settings.js index 0c2da4d3..e5b9783a 100644 --- a/models/settings.js +++ b/models/settings.js @@ -20,6 +20,10 @@ Settings.attachSchema(new SimpleSchema({ type: String, optional: true, }, + 'mailServer.enableTLS': { + type: Boolean, + optional: true, + }, 'mailServer.from': { type: String, optional: true, @@ -38,10 +42,11 @@ Settings.helpers({ if (!this.mailServer.host) { return null; } + const protocol = this.mailServer.enableTLS ? 'smtps://' : 'smtp://'; if (!this.mailServer.username && !this.mailServer.password) { - return `smtp://${this.mailServer.host}:${this.mailServer.port}/`; + return `${protocol}${this.mailServer.host}:${this.mailServer.port}/`; } - return `smtp://${this.mailServer.username}:${this.mailServer.password}@${this.mailServer.host}:${this.mailServer.port}/`; + return `${protocol}${this.mailServer.username}:${this.mailServer.password}@${this.mailServer.host}:${this.mailServer.port}/`; }, }); Settings.allow({ @@ -62,7 +67,7 @@ if (Meteor.isServer) { if(!setting){ const now = new Date(); const defaultSetting = {disableRegistration: false, mailServer: { - username: '', password:'', host: '', port:'', from: '', + username: '', password: '', host: '', port: '', enableTLS: false, from: '', }, createdAt: now, modifiedAt: now}; Settings.insert(defaultSetting); } @@ -72,11 +77,12 @@ if (Meteor.isServer) { }); Settings.after.update((userId, doc, fieldNames) => { // assign new values to mail-from & MAIL_URL in environment - if (_.contains(fieldNames, 'mailServer') && _.contains(fieldNames, 'host')) { + if (_.contains(fieldNames, 'mailServer') && doc.mailServer.host) { + const protocol = doc.mailServer.enableTLS ? 'smtps://' : 'smtp://'; if (!doc.mailServer.username && !doc.mailServer.password) { - process.env.MAIL_URL = `smtp://${doc.mailServer.host}:${doc.mailServer.port}/`; + process.env.MAIL_URL = `${protocol}${doc.mailServer.host}:${doc.mailServer.port}/`; } else { - process.env.MAIL_URL = `smtp://${doc.mailServer.username}:${doc.mailServer.password}@${doc.mailServer.host}:${doc.mailServer.port}/`; + process.env.MAIL_URL = `${protocol}${doc.mailServer.username}:${doc.mailServer.password}@${doc.mailServer.host}:${doc.mailServer.port}/`; } Accounts.emailTemplates.from = doc.mailServer.from; } -- cgit v1.2.3-1-g7c22