From 1c2518fe22e2cfe25c3f98fd6b0bb0c6372ac526 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 18 Jan 2016 13:22:15 -0500 Subject: [PATCH] Using sendmail instead of direct transport Squashed commit of the following: commit 9d4937fff6f6a1b4327fed0ada32153bd7e07efd Author: Julian Lam Date: Mon Jan 18 13:21:52 2016 -0500 Revert "added some debug code" This reverts commit 2dd8535c7bd8f59b8ed59c8b98b5484a79fa0500. commit 2dd8535c7bd8f59b8ed59c8b98b5484a79fa0500 Author: Julian Lam Date: Mon Jan 18 12:04:02 2016 -0500 added some debug code commit af8ca8241e66fd538089517e7722c644668667f2 Author: Julian Lam Date: Mon Jan 18 11:50:41 2016 -0500 using sendmail instead of direct transport --- package.json | 3 ++- src/emailer.js | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4a9355061d..d563edef32 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,8 @@ "nodebb-theme-persona": "4.0.59", "nodebb-theme-vanilla": "5.0.29", "nodebb-widget-essentials": "2.0.5", - "nodemailer": "0.7.1", + "nodemailer": "2.0.0", + "nodemailer-sendmail-transport": "1.0.0", "passport": "^0.3.0", "passport-local": "1.0.0", "postcss": "^5.0.13", diff --git a/src/emailer.js b/src/emailer.js index e6cb6366a3..7e2466b09f 100644 --- a/src/emailer.js +++ b/src/emailer.js @@ -5,6 +5,7 @@ var async = require('async'), nconf = require('nconf'), templates = require('templates.js'), nodemailer = require('nodemailer'), + sendmailTransport = require('nodemailer-sendmail-transport'), htmlToText = require('html-to-text'), url = require('url'), @@ -14,10 +15,10 @@ var async = require('async'), translator = require('../public/src/modules/translator'), transports = { - direct: nodemailer.createTransport('direct'), + sendmail: nodemailer.createTransport(sendmailTransport()), gmail: undefined }, - app; + app, fallbackTransport; (function(Emailer) { Emailer.registerApp = function(expressApp) { @@ -25,13 +26,15 @@ var async = require('async'), // Enable Gmail transport if enabled in ACP if (parseInt(meta.config['email:GmailTransport:enabled'], 10) === 1) { - transports.gmail = nodemailer.createTransport('SMTP', { + fallbackTransport = transports.gmail = nodemailer.createTransport('SMTP', { service: 'Gmail', auth: { user: meta.config['email:GmailTransport:user'], pass: meta.config['email:GmailTransport:pass'] } }); + } else { + fallbackTransport = transports.sendmail; } return Emailer; @@ -119,7 +122,7 @@ var async = require('async'), delete data.from_name; winston.verbose('[emailer] Sending email to uid ' + data.uid); - transports[transports.gmail ? 'gmail' : 'direct'].sendMail(data, callback); + fallbackTransport.sendMail(data, callback); }; function render(tpl, params, next) {