mailgun-js-boland: Send mail, and return undefined

8.0.0 on Mac OS X

const mailgun = new Mailgun({
    apiKey: <API key>,
    domain: <API Base URL>,
});

const data = {
    from: '<Default SMTP Login>',
    to: user.email,
    subject: '<Subjet>',
    html: `<context>`
}

mailgun.messages().send(data, function (err, body) {
    if (err) {
        console.log("got an error: ", err);
    }
    else {
        console.log(body);
    }
});

When I try to log out the body, It just keep returning undefined but didn’t return an error?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15

Most upvoted comments

Spent a while debugging this same error before I came across this issue. I was using the full api url https://api.mailgun.net/v3/<domain> instead of just domain.

Definitely a user error but a proper error message would have helped. Even if it was just an ‘invalid domain’ error.

Hmm domain should just be something like: 'sandbox12345.mailgun.org'. http://bojand.github.io/mailgun-js/#/?id=options

Uploading Screen Shot 2020-05-31 at 6.18.54 PM.png…

Thank you all for sharing your experience. Here is my experience. I agreed with you all that a proper error message would have saved the day for any developer having this issue. In addition to that, I think mailgun would have to make copying the domain a lot easier by adding a copy functionality(like click board icon) to that page. Most newbies just get the URL instead of the domain itself. The domain is the part that starts with sandbox....

Of course, how blind of me. Anyway the proper error message would have been a lot convenient.

Ok, thanks. I went to https://app.mailgun.com/app/domains and found the correct domain for my account. I had tried domains from other sources, but the one I found there works.

For me the problem is consistent, and curl works fine. I should also note that the email never sends with mailgun-js. It will send if I use curl though.

When I use the DEBUG environment variable, here’s what I get. The x’s after the V3 were put there by me since I figured that identified my account, and the “undefined” on the line by itself is from a console.log that I added.

  mailgun-js POST /v3/https://api.mailgun.net/v3/sandboxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org/messages/messages +0ms
POST /contactform 200 310.285 ms - -
  mailgun-js response status code: 200 content type: application/octet-stream error: undefined +179ms
undefined