|
|
@ -31,10 +31,17 @@ var EMAIL_TYPES = { |
|
|
|
|
|
|
|
|
|
|
|
function EmailService(opts) { |
|
|
|
$.checkArgument(opts); |
|
|
|
|
|
|
|
opts.email = opts.email || {}; |
|
|
|
|
|
|
|
this.storage = opts.storage; |
|
|
|
this.lock = opts.lock; |
|
|
|
this.mailer = opts.mailer || nodemailer.createTransport(opts.email); |
|
|
|
this.from = opts.email.from; |
|
|
|
|
|
|
|
$.checkState(this.mailer); |
|
|
|
$.checkState(this.from); |
|
|
|
}; |
|
|
|
|
|
|
|
// TODO: cache for X minutes
|
|
|
@ -95,7 +102,7 @@ EmailService.prototype._getDataForTemplate = function(notification, cb) { |
|
|
|
data.walletM = wallet.m; |
|
|
|
data.walletN = wallet.n; |
|
|
|
var copayer = _.find(wallet.copayers, { |
|
|
|
copayerId: notification.creatorId |
|
|
|
id: notification.creatorId |
|
|
|
}); |
|
|
|
if (copayer) { |
|
|
|
data.creatorId = copayer.id; |
|
|
@ -162,6 +169,7 @@ EmailService.prototype.sendEmail = function(notification, cb) { |
|
|
|
var email = Model.Email.create({ |
|
|
|
walletId: notification.walletId, |
|
|
|
copayerId: recipient.copayerId, |
|
|
|
from: self.from, |
|
|
|
to: recipient.emailAddress, |
|
|
|
subject: content.subject, |
|
|
|
body: content.body, |
|
|
@ -174,7 +182,9 @@ EmailService.prototype.sendEmail = function(notification, cb) { |
|
|
|
function(emails, next) { |
|
|
|
async.each(emails, function(email, next) { |
|
|
|
self._send(email, next); |
|
|
|
}, next); |
|
|
|
}, function(err) { |
|
|
|
return next(); |
|
|
|
}); |
|
|
|
}, |
|
|
|
], cb); |
|
|
|
}; |
|
|
|