noa-dev noa-dev - 3 months ago 37
Node.js Question

Sending mail with mailgun through node.js - requested URL not found

my stack: node.js with Express 4.x
mailgun module: mailgun-js

I currently developing on my local machine and trying to send some simple confirmation email as shown in this module example:

var api_key = 'key-xxx';
var domain = 'http://mg.xxx.com/';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

var data = {
from: 'Billing <no-reply@mydomain.com>',
to: data.email,
subject: 'Thanks for buying ' + data.product,
text: 'You can create your plan right now or visist http://www.someurl.com later.'
};

mailgun.messages().send(data, function (err, body) {
if(err){
console.log(err);
}
console.log("mail sent", body);
});


According to this example this should work, unfortunate I keep getting the following error :

{ [Error: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.</p><p>If you entered the URL manually please check your spelling and try again.</p>
] statusCode: 404 }


When I change the domain to :
"mg.xxx.com"
without the http then I get this error:

{ [Error: Domain not found: md.xxx.com] statusCode: 404 }


I don't know where to start debugging this - maybe it doesnt work locally?

Already fixed - the problem was that I wrote md instead of mg

Answer

It was a typo that I made at the variable declaration:

var domain = 'http://mg.xxx.com/';

correct:

var domain = 'http://md.xxx.com/';