mailgun / mailgun-js-boland

A simple Node.js helper module for Mailgun API.
http://bojand.github.io/mailgun-js
MIT License
894 stars 122 forks source link

Domain not found for custom domain, but works with sandbox domain #236

Closed Martin36 closed 5 years ago

Martin36 commented 5 years ago

mailgun-js@0.22.0 Windows 10 Node version: 10.3.0

I get this error when trying to send mails using a custom domain:

Error: Domain not found: mg.bandmate.xyz at IncomingMessage.res.on (C:\Users\Martin\Documents\BandMate\server\node_modules\mailgun-js\lib\request.js:327:17) at IncomingMessage.emit (events.js:187:15) at endReadableNT (_stream_readable.js:1090:12) at process._tickCallback (internal/process/next_tick.js:63:19)

It works when I send a mail from this domain using curl and everything works when I use the sandbox domain but when I change to the custom one that error shows. Here is the code that I use for sending the email:

const emailConfig = {
    apiKey: 'XXXXXXXXXXXXXXX',
    domain: 'mg.bandmate.xyz'
}; 

const mailgun = require('mailgun-js')(emailConfig);

const data = {
      from: 'Martin via BandMate my@email.com',
      to: 'other@email.com',
      subject: 'Message from Martin',
      text: 'Hi',
}

mailgun.messages().send(data, (error, body) => {
      if(error) throw error;
      console.log(body);
})
Martin36 commented 5 years ago

I solved it. Had to change the emailConfig to use the host for EU instead

const emailConfig = {
    apiKey: 'XXXXXXXXXXXXXXX',
    domain: 'mg.bandmate.xyz',
    host: 'api.eu.mailgun.net'
};
nephix commented 5 years ago

Thanks for this @Martin36 this saved me from spending another 6hrs on the issue!

Matiyeu commented 5 years ago

Close the issue @Martin36 ;)