Smtp emailer change without restart (#5957)

* SMTP fallback transport setup during app startup and config update

* Verbose logging message to see when SMTP fallback transport is setup
v1.18.x
Dravere 7 years ago committed by Barış Soner Uşaklı
parent 098b8d9971
commit 8d5ef79e9c

@ -36,44 +36,28 @@ Emailer.listServices = function (callback) {
Emailer._defaultPayload = {};
Emailer.registerApp = function (expressApp) {
app = expressApp;
var logo = null;
if (meta.configs.hasOwnProperty('brand:emailLogo')) {
logo = (!meta.config['brand:emailLogo'].startsWith('http') ? nconf.get('url') : '') + meta.config['brand:emailLogo'];
}
Emailer._defaultPayload = {
url: nconf.get('url'),
site_title: meta.config.title || 'NodeBB',
logo: {
src: logo,
height: meta.config['brand:emailLogo:height'],
width: meta.config['brand:emailLogo:width'],
},
};
Emailer.setupFallbackTransport = function (config) {
winston.verbose('[emailer] Setting up SMTP fallback transport');
// Enable Gmail transport if enabled in ACP
if (parseInt(meta.config['email:smtpTransport:enabled'], 10) === 1) {
if (parseInt(config['email:smtpTransport:enabled'], 10) === 1) {
var smtpOptions = {};
if (meta.config['email:smtpTransport:user'] || meta.config['email:smtpTransport:pass']) {
if (config['email:smtpTransport:user'] || config['email:smtpTransport:pass']) {
smtpOptions.auth = {
user: meta.config['email:smtpTransport:user'],
pass: meta.config['email:smtpTransport:pass'],
user: config['email:smtpTransport:user'],
pass: config['email:smtpTransport:pass'],
};
}
if (meta.config['email:smtpTransport:service'] === 'nodebb-custom-smtp') {
smtpOptions.port = meta.config['email:smtpTransport:port'];
smtpOptions.host = meta.config['email:smtpTransport:host'];
if (config['email:smtpTransport:service'] === 'nodebb-custom-smtp') {
smtpOptions.port = config['email:smtpTransport:port'];
smtpOptions.host = config['email:smtpTransport:host'];
if (meta.config['email:smtpTransport:security'] === 'NONE') {
if (config['email:smtpTransport:security'] === 'NONE') {
smtpOptions.secure = false;
smtpOptions.requireTLS = false;
smtpOptions.ignoreTLS = true;
} else if (meta.config['email:smtpTransport:security'] === 'STARTTLS') {
} else if (config['email:smtpTransport:security'] === 'STARTTLS') {
smtpOptions.secure = false;
smtpOptions.requireTLS = true;
smtpOptions.ignoreTLS = false;
@ -84,7 +68,7 @@ Emailer.registerApp = function (expressApp) {
smtpOptions.ignoreTLS = false;
}
} else {
smtpOptions.service = meta.config['email:smtpTransport:service'];
smtpOptions.service = config['email:smtpTransport:service'];
}
transports.smtp = nodemailer.createTransport(smtpOptions);
@ -92,10 +76,34 @@ Emailer.registerApp = function (expressApp) {
} else {
fallbackTransport = transports.sendmail;
}
};
Emailer.registerApp = function (expressApp) {
app = expressApp;
var logo = null;
if (meta.configs.hasOwnProperty('brand:emailLogo')) {
logo = (!meta.config['brand:emailLogo'].startsWith('http') ? nconf.get('url') : '') + meta.config['brand:emailLogo'];
}
Emailer._defaultPayload = {
url: nconf.get('url'),
site_title: meta.config.title || 'NodeBB',
logo: {
src: logo,
height: meta.config['brand:emailLogo:height'],
width: meta.config['brand:emailLogo:width'],
},
};
Emailer.setupFallbackTransport(meta.config);
// Update default payload if new logo is uploaded
pubsub.on('config:update', function (config) {
if (config) {
if ('email:smtpTransport:enabled' in config) {
Emailer.setupFallbackTransport(config);
}
Emailer._defaultPayload.logo.src = config['brand:emailLogo'];
Emailer._defaultPayload.logo.height = config['brand:emailLogo:height'];
Emailer._defaultPayload.logo.width = config['brand:emailLogo:width'];

Loading…
Cancel
Save