noa-dev noa-dev - 6 months ago 125
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 = '';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

var data = {
from: 'Billing <>',
subject: 'Thanks for buying ' + data.product,
text: 'You can create your plan right now or visist later.'

mailgun.messages().send(data, function (err, body) {
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 :
without the http then I get this error:

{ [Error: Domain not found:] 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


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

var domain = '';


var domain = '';