mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +01:00
Update Nodemailer to v4
also filter out .jst files from email template dropdowns
This commit is contained in:
@@ -70,9 +70,7 @@
|
||||
"nodebb-theme-slick": "1.1.1",
|
||||
"nodebb-theme-vanilla": "6.0.26",
|
||||
"nodebb-widget-essentials": "3.0.4",
|
||||
"nodemailer": "2.6.4",
|
||||
"nodemailer-sendmail-transport": "1.0.0",
|
||||
"nodemailer-smtp-transport": "^2.4.1",
|
||||
"nodemailer": "4.1.0",
|
||||
"passport": "^0.3.0",
|
||||
"passport-local": "1.0.0",
|
||||
"postcss": "6.0.10",
|
||||
|
||||
@@ -4,13 +4,21 @@
|
||||
"address-help": "The following email address refers to the email that the recipient will see in the \"From\" and \"Reply To\" fields.",
|
||||
"from": "From Name",
|
||||
"from-help": "The from name to display in the email.",
|
||||
"gmail-routing": "Gmail Routing",
|
||||
"gmail-routing-help1": "There have been reports of Gmail Routing not working on accounts with heightened security. In those scenarios, you will have to <a href=\"https://www.google.com/settings/security/lesssecureapps\">configure your GMail account to allow less secure apps</a>.",
|
||||
"gmail-routing-help2": "For more information about this workaround, <a href=\"https://nodemailer.com/using-gmail/\">please consult this NodeMailer article on the issue.</a> An alternative would be to utilise a third-party emailer plugin such as SendGrid, Mailgun, etc. <a href=\"{config.relative_path}/admin/extend/plugins\">Browse available plugins here</a>.",
|
||||
"gmail-transport": "Route emails through a Gmail/Google Apps account",
|
||||
"gmail-transport.username": "Username",
|
||||
"gmail-transport.username-help": "Enter the full email address here, especially if you are using a Google Apps managed domain.",
|
||||
"gmail-transport.password": "Password",
|
||||
|
||||
"smtp-transport": "SMTP Transport",
|
||||
"smtp-transport.enabled": "Use an external email server to send emails",
|
||||
"smtp-transport-help": "You can select from a list of well-known services or enter a custom one.",
|
||||
"smtp-transport.service": "Select a service",
|
||||
"smtp-transport.service-custom": "Custom Service",
|
||||
"smtp-transport.service-help": "Select a service name above in order to use the known information about it. Alternatively, select 'Custom Service' and enter the details below.",
|
||||
"smtp-transport.gmail-warning1": "There have been reports of the Gmail service not working on accounts with heightened security. In those scenarios, you will have to <a href=\"https://www.google.com/settings/security/lesssecureapps\">configure your GMail account to allow less secure apps</a>.",
|
||||
"smtp-transport.gmail-warning2": "For more information about this workaround, <a href=\"https://nodemailer.com/usage/using-gmail/\">please consult this NodeMailer article on the issue.</a> An alternative would be to utilise a third-party emailer plugin such as SendGrid, Mailgun, etc. <a href=\"{config.relative_path}/admin/extend/plugins\">Browse available plugins here</a>.",
|
||||
"smtp-transport.host": "SMTP Host",
|
||||
"smtp-transport.port": "SMTP Port",
|
||||
"smtp-transport.username": "Username",
|
||||
"smtp-transport.username-help": "<b>For the Gmail service,</b> enter the full email address here, especially if you are using a Google Apps managed domain.",
|
||||
"smtp-transport.password": "Password",
|
||||
|
||||
"template": "Edit Email Template",
|
||||
"template.select": "Select Email Template",
|
||||
"template.revert": "Revert to Original",
|
||||
|
||||
@@ -9,11 +9,13 @@ define('admin/settings/email', ['ace/ace', 'admin/settings'], function (ace) {
|
||||
configureEmailTester();
|
||||
configureEmailEditor();
|
||||
handleDigestHourChange();
|
||||
handleSmtpServiceChange();
|
||||
|
||||
$(window).on('action:admin.settingsLoaded action:admin.settingsSaved', handleDigestHourChange);
|
||||
$(window).on('action:admin.settingsSaved', function () {
|
||||
socket.emit('admin.user.restartJobs');
|
||||
});
|
||||
$('[id="email:smtpTransport:service"]').change(handleSmtpServiceChange);
|
||||
};
|
||||
|
||||
function configureEmailTester() {
|
||||
@@ -100,5 +102,10 @@ define('admin/settings/email', ['ace/ace', 'admin/settings'], function (ace) {
|
||||
});
|
||||
}
|
||||
|
||||
function handleSmtpServiceChange() {
|
||||
var isCustom = $('[id="email:smtpTransport:service"]').val() === 'nodebb-custom-smtp';
|
||||
$('[id="email:smtpTransport:custom-service"]')[isCustom ? 'slideDown' : 'slideUp'](isCustom);
|
||||
}
|
||||
|
||||
return module;
|
||||
});
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var meta = require('../../meta');
|
||||
var file = require('../../file');
|
||||
var emailer = require('../../emailer');
|
||||
|
||||
var settingsController = module.exports;
|
||||
|
||||
@@ -22,17 +26,20 @@ settingsController.get = function (req, res, next) {
|
||||
|
||||
|
||||
function renderEmail(req, res, next) {
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var file = require('../../file');
|
||||
|
||||
var emailsPath = path.join(nconf.get('views_dir'), 'emails');
|
||||
|
||||
async.parallel({
|
||||
emails: function (cb) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
file.walk(emailsPath, next);
|
||||
},
|
||||
function (emails, next) {
|
||||
// exclude .jst files
|
||||
emails = emails.filter(function (email) {
|
||||
return !email.endsWith('.jst');
|
||||
});
|
||||
|
||||
async.map(emails, function (email, next) {
|
||||
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
|
||||
|
||||
@@ -53,13 +60,20 @@ function renderEmail(req, res, next) {
|
||||
], next);
|
||||
}, next);
|
||||
},
|
||||
function (emails) {
|
||||
], cb);
|
||||
},
|
||||
services: emailer.listServices,
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('admin/settings/email', {
|
||||
emails: emails,
|
||||
sendable: emails.filter(function (email) {
|
||||
emails: results.emails,
|
||||
sendable: results.emails.filter(function (email) {
|
||||
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
|
||||
}),
|
||||
services: results.services,
|
||||
});
|
||||
});
|
||||
},
|
||||
], next);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ var winston = require('winston');
|
||||
var nconf = require('nconf');
|
||||
var Benchpress = require('benchpressjs');
|
||||
var nodemailer = require('nodemailer');
|
||||
var sendmailTransport = require('nodemailer-sendmail-transport');
|
||||
var smtpTransport = require('nodemailer-smtp-transport');
|
||||
var wellKnownServices = require('nodemailer/lib/well-known/services');
|
||||
var htmlToText = require('html-to-text');
|
||||
var url = require('url');
|
||||
|
||||
@@ -17,8 +16,12 @@ var translator = require('./translator');
|
||||
var pubsub = require('./pubsub');
|
||||
|
||||
var transports = {
|
||||
sendmail: nodemailer.createTransport(sendmailTransport()),
|
||||
gmail: undefined,
|
||||
sendmail: nodemailer.createTransport({
|
||||
sendmail: true,
|
||||
newline: 'unix',
|
||||
}),
|
||||
smtp: undefined,
|
||||
// gmail: undefined,
|
||||
};
|
||||
|
||||
var app;
|
||||
@@ -26,6 +29,11 @@ var fallbackTransport;
|
||||
|
||||
var Emailer = module.exports;
|
||||
|
||||
Emailer.listServices = function (callback) {
|
||||
var services = Object.keys(wellKnownServices);
|
||||
setImmediate(callback, null, services);
|
||||
};
|
||||
|
||||
Emailer._defaultPayload = {};
|
||||
|
||||
Emailer.registerApp = function (expressApp) {
|
||||
@@ -47,17 +55,24 @@ Emailer.registerApp = function (expressApp) {
|
||||
};
|
||||
|
||||
// Enable Gmail transport if enabled in ACP
|
||||
if (parseInt(meta.config['email:GmailTransport:enabled'], 10) === 1) {
|
||||
transports.gmail = nodemailer.createTransport(smtpTransport({
|
||||
host: 'smtp.gmail.com',
|
||||
port: 465,
|
||||
secure: true,
|
||||
if (parseInt(meta.config['email:smtpTransport:enabled'], 10) === 1) {
|
||||
var smtpOptions = {
|
||||
auth: {
|
||||
user: meta.config['email:GmailTransport:user'],
|
||||
pass: meta.config['email:GmailTransport:pass'],
|
||||
user: meta.config['email:smtpTransport:user'],
|
||||
pass: meta.config['email:smtpTransport:pass'],
|
||||
},
|
||||
}));
|
||||
fallbackTransport = transports.gmail;
|
||||
};
|
||||
|
||||
if (meta.config['email:smtpTransport:serice'] === 'nodebb-custom-smtp') {
|
||||
smtpOptions.port = meta.config['email:smtpTransport:port'];
|
||||
smtpOptions.host = meta.config['email:smtpTransport:host'];
|
||||
smtpOptions.secure = true;
|
||||
} else {
|
||||
smtpOptions.service = meta.config['email:smtpTransport:service'];
|
||||
}
|
||||
|
||||
transports.smtp = nodemailer.createTransport(smtpOptions);
|
||||
fallbackTransport = transports.smtp;
|
||||
} else {
|
||||
fallbackTransport = transports.sendmail;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<div class="form-group">
|
||||
<label for="email:from"><strong>[[admin/settings/email:address]]</strong></label>
|
||||
<p class="help-block">
|
||||
|
||||
[[admin/settings/email:address-help]]
|
||||
</p>
|
||||
<input type="text" class="form-control input-lg" id="email:from" data-field="email:from" placeholder="info@example.org" /><br />
|
||||
</div>
|
||||
@@ -23,33 +23,57 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/email:gmail-routing]]</div>
|
||||
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/email:smtp-transport]]</div>
|
||||
<div class="col-sm-10 col-xs-12">
|
||||
<div class="alert alert-warning">
|
||||
<p>
|
||||
[[admin/settings/email:gmail-routing-help1]]
|
||||
</p>
|
||||
<p>
|
||||
[[admin/settings/email:gmail-routing-help2]]
|
||||
[[admin/settings/email:smtp-transport-help]]
|
||||
</p>
|
||||
</div>
|
||||
<form>
|
||||
<div class="checkbox">
|
||||
<label for="email:GmailTransport:enabled" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input class="mdl-switch__input" type="checkbox" id="email:GmailTransport:enabled" data-field="email:GmailTransport:enabled" name="email:GmailTransport:enabled" />
|
||||
<span class="mdl-switch__label">[[admin/settings/email:gmail-transport]]</span>
|
||||
<label for="email:smtpTransport:enabled" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input class="mdl-switch__input" type="checkbox" id="email:smtpTransport:enabled" data-field="email:smtpTransport:enabled" name="email:smtpTransport:enabled" />
|
||||
<span class="mdl-switch__label">[[admin/settings/email:smtp-transport.enabled]]</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email:GmailTransport:user"><strong>[[admin/settings/email:gmail-transport.username]]</strong></label>
|
||||
<input type="text" class="form-control input-lg" id="email:GmailTransport:user" data-field="email:GmailTransport:user" placeholder="admin@example.org" />
|
||||
<label for="email:smtpTransport:service"><strong>[[admin/settings/email:smtp-transport.service]]</strong></label>
|
||||
<select class="form-control input-lg" id="email:smtpTransport:service" data-field="email:smtpTransport:service">
|
||||
<!-- BEGIN services -->
|
||||
<option value="@value">@value</option>
|
||||
<!-- END services -->
|
||||
|
||||
<option style="font-size: 10px" disabled> </option>
|
||||
<option value="nodebb-custom-smtp" style="font-weight: bold">[[admin/settings/email:smtp-transport.service-custom]]</option>
|
||||
</select>
|
||||
<p class="help-block">
|
||||
[[admin/settings/email:gmail-transport.username-help]]
|
||||
[[admin/settings/email:smtp-transport.service-help]]
|
||||
<br>
|
||||
[[admin/settings/email:smtp-transport.gmail-warning1]]
|
||||
<br>
|
||||
[[admin/settings/email:smtp-transport.gmail-warning2]]
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-group well" id="email:smtpTransport:custom-service" style="display: none">
|
||||
<h5>Custom Service</h5>
|
||||
|
||||
<label for="email:smtpTransport:host">[[admin/settings/email:smtp-transport.host]]</label>
|
||||
<input type="text" class="form-control input-md" id="email:smtpTransport:host" data-field="email:smtpTransport:host" placeholder="smtp.example.org">
|
||||
|
||||
<label for="email:smtpTransport:port">[[admin/settings/email:smtp-transport.port]]</label>
|
||||
<input type="text" class="form-control input-md" id="email:smtpTransport:port" data-field="email:smtpTransport:port" placeholder="5555">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email:smtpTransport:user"><strong>[[admin/settings/email:smtp-transport.username]]</strong></label>
|
||||
<input type="text" class="form-control input-lg" id="email:smtpTransport:user" data-field="email:smtpTransport:user" placeholder="admin@example.org" />
|
||||
<p class="help-block">
|
||||
[[admin/settings/email:smtp-transport.username-help]]
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email:GmailTransport:pass"><strong>[[admin/settings/email:gmail-transport.password]]</strong></label>
|
||||
<input type="password" class="form-control input-lg" id="email:GmailTransport:pass" data-field="email:GmailTransport:pass" />
|
||||
<label for="email:smtpTransport:pass"><strong>[[admin/settings/email:smtp-transport.password]]</strong></label>
|
||||
<input type="password" class="form-control input-lg" id="email:smtpTransport:pass" data-field="email:smtpTransport:pass" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user