Skip to content
Snippets Groups Projects
Commit 3fb258f8 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

🐞 Bugfix: don't use the mandrill api if we don't have an api key

parent a0b66f66
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -7,33 +7,43 @@ exports.create = function(options) {
var stats = options.stats;
var logger = options.logger;
 
var mandrillClient = require('mandrill-api/mandrill');
var mandrill = new mandrillClient.Mandrill(config.get('mandrill:apiKey'));
/* Promisify mandrill's wierd api */
function sendTemplate(options) {
return new Promise(function(resolve, reject) {
mandrill.messages.sendTemplate(options, function(result) {
var first = result[0];
if(first.status === 'rejected' || first.status === 'invalid') {
return reject(new Error('Email provider rejected email: ' + (first.reject_reason || first.status)));
}
var mandrillApiKey = config.get('mandrill:apiKey')
var sendTemplate;
if (mandrillApiKey) {
var mandrillClient = require('mandrill-api/mandrill');
var mandrill = new mandrillClient.Mandrill(mandrillApiKey);
/* Promisify mandrill's wierd api */
sendTemplate = function sendTemplateMandrill(options) {
return new Promise(function(resolve, reject) {
mandrill.messages.sendTemplate(options, function(result) {
var first = result[0];
if(first.status === 'rejected' || first.status === 'invalid') {
return reject(new Error('Email provider rejected email: ' + (first.reject_reason || first.status)));
}
/* Resolve */
resolve({
id: first._id,
status: first.status
});
 
/* Resolve */
resolve({
id: first._id,
status: first.status
});
}, function(err) {
if(!(err instanceof Error) && err.message) {
return reject(new Error(err.message));
}
 
}, function(err) {
if(!(err instanceof Error) && err.message) {
return reject(new Error(err.message));
}
reject(err);
});
 
reject(err);
});
});
}
} else {
// Just use a fake mailer
sendTemplate = function () {
return Promise.resolve({ fake: true });
}
}
 
/* Resolve all the values in a hash */
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment