upgrade to nodemailer 2.0 and dynamically use either SES or SMTP depending

on what is in settings file
This commit is contained in:
Henry Oswald 2016-02-12 17:13:45 +00:00
parent 0538ca2de5
commit 05bf048885
2 changed files with 23 additions and 11 deletions

View file

@ -3,6 +3,8 @@ metrics = require('../../infrastructure/Metrics')
Settings = require('settings-sharelatex')
metrics = require("../../infrastructure/Metrics")
nodemailer = require("nodemailer")
sesTransport = require('nodemailer-ses-transport')
_ = require("underscore")
if Settings.email? and Settings.email.fromAddress?
defaultFromAddress = Settings.email.fromAddress
@ -15,15 +17,25 @@ client =
logger.log options:options, "Would send email if enabled."
callback()
if Settings.email?
if Settings.email.transport? and Settings.email.parameters?
nm_client = nodemailer.createTransport( Settings.email.transport, Settings.email.parameters )
if nm_client
client = nm_client
else
logger.warn "Failed to create email transport. Please check your settings. No email will be sent."
else
logger.warn "Email transport and/or parameters not defined. No emails will be sent."
if Settings?.email?.parameters?.AWSAccessKeyID?
logger.log "using aws ses for email"
nm_client = nodemailer.createTransport(sesTransport(Settings.email.parameters))
else if Settings?.email?.parameters?
smtp = _.pick(Settings?.email?.parameters, "host", "port", "secure", "auth")
logger.log "using smtp for email"
console.log smtp
nm_client = nodemailer.createTransport(smtp)
else
nm_client = client
logger.warn "Email transport and/or parameters not defined. No emails will be sent."
if nm_client?
client = nm_client
else
logger.warn "Failed to create email transport. Please check your settings. No email will be sent."
module.exports =
sendEmail : (options, callback = (error) ->)->
@ -42,4 +54,3 @@ module.exports =
else
logger.log "Message sent to #{options.to}"
callback(err)

View file

@ -38,7 +38,8 @@
"mongoose": "4.1.0",
"multer": "^0.1.8",
"node-uuid": "1.4.1",
"nodemailer": "0.6.1",
"nodemailer": "2.1.0",
"nodemailer-ses-transport": "^1.3.0",
"optimist": "0.6.1",
"redback": "0.4.0",
"redis": "0.10.1",