Merge pull request #328 from sharelatex/sk-plain-text-email

Sk plain text email
This commit is contained in:
Shane Kilkelly 2016-10-05 10:04:08 +01:00 committed by GitHub
commit 95a66bbf00
7 changed files with 76 additions and 7 deletions

View file

@ -82,7 +82,7 @@ module.exports = CollaboratorsInviteHandler =
if err?
logger.err {projectId, email}, "error sending messages for invite"
callback(null, invite)
revokeInvite: (projectId, inviteId, callback=(err)->) ->
logger.log {projectId, inviteId}, "removing invite"
@ -104,7 +104,7 @@ module.exports = CollaboratorsInviteHandler =
return callback(null)
CollaboratorsInviteHandler._sendMessages projectId, sendingUser, invite, (err) ->
if err?
logger.err {projectid, inviteId}, "error resending invite messages"
logger.err {projectId, inviteId}, "error resending invite messages"
return callback(err)
callback(null)

View file

@ -91,6 +91,15 @@ templates.projectInvite =
subject: _.template "<%= project.name %> - shared by <%= owner.email %>"
layout: NotificationEmailLayout
type:"notification"
plainTextTemplate: _.template """
Hi, <%= owner.email %> wants to share '<%= project.name %>' with you.
Follow this link to view the project: <%= inviteUrl %>
Thank you
#{settings.appName} - <%= siteUrl %>
"""
compiledTemplate: _.template """
<p>Hi, <%= owner.email %> wants to share <a href="<%= project.url %>">'<%= project.name %>'</a> with you</p>
<center>
@ -137,5 +146,6 @@ module.exports =
return {
subject : template.subject(opts)
html: template.layout(opts)
text: template?.plainTextTemplate?(opts)
type:template.type
}

View file

@ -3,7 +3,7 @@ EmailBuilder = require "./EmailBuilder"
EmailSender = require "./EmailSender"
if !settings.email?
settings.email =
settings.email =
lifecycleEnabled:false
@ -14,6 +14,7 @@ module.exports =
if email.type == "lifecycle" and !settings.email.lifecycle
return callback()
opts.html = email.html
opts.text = email.text
opts.subject = email.subject
EmailSender.sendEmail opts, (err)->
callback(err)
callback(err)

View file

@ -49,6 +49,7 @@ module.exports =
from: defaultFromAddress
subject: options.subject
html: options.html
text: options.text
replyTo: options.replyTo || Settings.email.replyToAddress
socketTimeout: 30 * 1000
client.sendMail options, (err, res)->

View file

@ -34,6 +34,31 @@ describe "EmailBuilder", ->
@email.html.indexOf(@opts.owner.email).should.not.equal -1
@email.subject.indexOf(@opts.owner.email).should.not.equal -1
it 'should not have text component', ->
expect(@email.html?).to.equal true
expect(@email.text?).to.equal false
it "should not have undefined in it", ->
@email.html.indexOf("undefined").should.equal -1
@email.subject.indexOf("undefined").should.equal -1
describe "projectInvite", ->
beforeEach ->
@opts =
to:"bob@bob.com"
first_name:"bob"
owner:
email:"sally@hally.com"
inviteUrl: "http://example.com/invite"
project:
url:"http://www.project.com"
name:"standard project"
@email = @EmailBuilder.buildEmail("projectInvite", @opts)
it 'should have html and text properties', ->
expect(@email.html?).to.equal true
expect(@email.text?).to.equal true
it "should not have undefined in it", ->
@email.html.indexOf("undefined").should.equal -1
@email.subject.indexOf("undefined").should.equal -1

View file

@ -10,9 +10,9 @@ describe "EmailHandler", ->
beforeEach ->
@settings =
@settings =
email:{}
@EmailBuilder =
@EmailBuilder =
buildEmail:sinon.stub()
@EmailSender =
sendEmail:sinon.stub()
@ -74,3 +74,19 @@ describe "EmailHandler", ->
@EmailHandler.sendEmail "welcome", opts, =>
@EmailSender.sendEmail.called.should.equal true
done()
describe 'with plain-text email content', () ->
beforeEach ->
@text = "hello there"
it 'should pass along the text field', (done) ->
@EmailBuilder.buildEmail.returns({html: @html, text: @text})
@EmailSender.sendEmail.callsArgWith(1)
opts =
to: "bob@bob.com"
@EmailHandler.sendEmail "welcome", opts, =>
args = @EmailSender.sendEmail.args[0][0]
args.html.should.equal @html
args.text.should.equal @text
done()

View file

@ -31,7 +31,7 @@ describe "EmailSender", ->
warn:->
err:->
"../../infrastructure/Metrics": inc:->
@opts =
@ -83,3 +83,19 @@ describe "EmailSender", ->
args = @sesClient.sendMail.args[0][0]
args.replyTo.should.equal @opts.replyTo
done()
describe 'with plain-text email content', () ->
beforeEach ->
@opts.text = "hello there"
it "should set the text property on the email to send", (done)->
@sesClient.sendMail.callsArgWith(1)
@sender.sendEmail @opts, =>
args = @sesClient.sendMail.args[0][0]
args.html.should.equal @opts.html
args.text.should.equal @opts.text
args.to.should.equal @opts.to
args.subject.should.equal @opts.subject
done()