|
|
@ -38,6 +38,7 @@ function EmailService(opts) { |
|
|
|
this.storage = opts.storage; |
|
|
|
this.lock = opts.lock; |
|
|
|
this.mailer = opts.mailer || nodemailer.createTransport(opts.email); |
|
|
|
this.subjectPrefix = opts.email.subjectPrefix || '[Wallet service]'; |
|
|
|
this.from = opts.email.from; |
|
|
|
|
|
|
|
$.checkState(this.mailer); |
|
|
@ -95,6 +96,7 @@ EmailService.prototype._getDataForTemplate = function(notification, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var data = _.cloneDeep(notification.data); |
|
|
|
data.subjectPrefix = _.trim(self.subjectPrefix) + ' '; |
|
|
|
self.storage.fetchWallet(notification.walletId, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
data.walletId = wallet.id; |
|
|
@ -175,7 +177,14 @@ EmailService.prototype.sendEmail = function(notification, cb) { |
|
|
|
}, |
|
|
|
function(emails, next) { |
|
|
|
async.each(emails, function(email, next) { |
|
|
|
self._send(email, next); |
|
|
|
self._send(email, function(err) { |
|
|
|
if (err) { |
|
|
|
email.setFail(); |
|
|
|
} else { |
|
|
|
email.setSent(); |
|
|
|
} |
|
|
|
self.storage.storeEmail(email, next); |
|
|
|
}); |
|
|
|
}, function(err) { |
|
|
|
return next(); |
|
|
|
}); |
|
|
|