From 4d41c67c546d15f87b58bc985114223bf0391017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 6 Dec 2016 15:58:27 +0100 Subject: [PATCH] Remove "options.template" from Email payload Fix User.confirm to exclude "options.template" when sending the confirmation email. Certain nodemailer transport plugins are rejecting such requests. --- common/models/user.js | 4 ++++ test/user.test.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/common/models/user.js b/common/models/user.js index 41ad6232..7cb72e20 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -469,6 +469,10 @@ module.exports = function(User) { function setHtmlContentAndSend(html) { options.html = html; + // Remove options.template to prevent rejection by certain + // nodemailer transport plugins. + delete options.template; + Email.send(options, function(err, email) { if (err) { fn(err); diff --git a/test/user.test.js b/test/user.test.js index f3b4b850..cd764ff5 100644 --- a/test/user.test.js +++ b/test/user.test.js @@ -1659,6 +1659,24 @@ describe('User', function() { done(); }); }); + + it('removes "options.template" from Email payload', function() { + var MailerMock = { + send: function(options, cb) { cb(null, options); }, + }; + + return User.create({email: 'user@example.com', password: 'pass'}) + .then(function(user) { + return user.verify({ + type: 'email', + from: 'noreply@example.com', + mailer: MailerMock, + }); + }) + .then(function(result) { + expect(result.email).to.not.have.property('template'); + }); + }); }); describe('User.confirm(options, fn)', function() {