diff --git a/mailgun.js b/mailgun.js index 3292d61..6ef1def 100755 --- a/mailgun.js +++ b/mailgun.js @@ -140,6 +140,10 @@ Mailgun.prototype.sendText = function(sender, recipients, subject, text) { if (callback) callback(res.statusCode != 201 ? new Error(res.statusCode) : undefined); }); + req.on('error', function(err) { + if (callback) callback(err); + }); + // Wrap up the request by sending the body, which contains the // actual email data we want to send. req.end(body); @@ -205,6 +209,10 @@ Mailgun.prototype.sendRaw = function(sender, recipients, rawBody) { if (callback) callback(res.statusCode != 201 ? new Error(res.statusCode) : undefined); }); + req.on('error', function(err) { + if (callback) callback(err); + }); + // Wrap up the request by sending the message, which contains the // actual email data we want to send. req.end(message);