email sending options are configurable from settings

This commit is contained in:
Henry Oswald 2014-03-05 11:31:40 +00:00
parent 5bacb2d784
commit 3c18cc5553
2 changed files with 38 additions and 15 deletions

View file

@ -20,10 +20,10 @@ module.exports =
metrics.inc "email" metrics.inc "email"
options = options =
to: options.to to: options.to
from: "ShareLaTeX <team@sharelatex.com>" from: Settings.email.fromAddress
subject: options.subject subject: options.subject
message: options.html message: options.html
replyTo: options.replyTo || "team@sharelatex.com" replyTo: Settings.email.replyToAddress
client.sendemail options, (err, data, res)-> client.sendemail options, (err, data, res)->
if err? if err?
logger.err err:err, "error sending message" logger.err err:err, "error sending message"

View file

@ -10,10 +10,14 @@ describe "Email", ->
beforeEach -> beforeEach ->
@settings = @settings =
ses: email:
key: "key" ses:
secret: "secret" key: "key"
secret: "secret"
fromAddress: "bob@bob.com"
replyToAddress: "sally@gmail.com"
@sesClient = @sesClient =
sendemail: sinon.stub() sendemail: sinon.stub()
@ses = @ses =
@ -26,21 +30,22 @@ describe "Email", ->
warn:-> warn:->
err:-> err:->
@opts =
to: "bob@bob.com"
subject: "new email"
html: "<hello></hello>"
replyTo: "sarah@bob.com"
describe "sendEmail", -> describe "sendEmail", ->
it "should set the properties on the email to send", (done)-> it "should set the properties on the email to send", (done)->
@sesClient.sendemail.callsArgWith(1) @sesClient.sendemail.callsArgWith(1)
opts = @sender.sendEmail @opts, =>
to: "bob@bob.com"
subject: "new email"
html: "<hello></hello>"
replyTo: "sarah@bob.com"
@sender.sendEmail opts, =>
args = @sesClient.sendemail.args[0][0] args = @sesClient.sendemail.args[0][0]
args.message.should.equal opts.html args.message.should.equal @opts.html
args.to.should.equal opts.to args.to.should.equal @opts.to
args.subject.should.equal opts.subject args.subject.should.equal @opts.subject
done() done()
it "should return the error", (done)-> it "should return the error", (done)->
@ -48,3 +53,21 @@ describe "Email", ->
@sender.sendEmail {}, (err)=> @sender.sendEmail {}, (err)=>
err.should.equal "error" err.should.equal "error"
done() done()
it "should use the from address from settings", (done)->
@sesClient.sendemail.callsArgWith(1)
@sender.sendEmail @opts, =>
args = @sesClient.sendemail.args[0][0]
args.from.should.equal @settings.email.fromAddress
done()
it "should use the reply to address from settings", (done)->
@sesClient.sendemail.callsArgWith(1)
@sender.sendEmail @opts, =>
args = @sesClient.sendemail.args[0][0]
args.replyTo.should.equal @settings.email.replyToAddress
done()