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
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 justdomain.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=optionsThank 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
DEBUGenvironment 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 aconsole.logthat I added.