mailgun.js: 'from' parameter is missing
I added mailgun-js to my project today, and have a problem sending messages.
My send code looks like this:
const data = {
from: "Mailgun Sandbox <postmaster@mail.optimiser.io>",
to: "derek@optimiser.io",
subject: "Hello",
template: "invite-client",
'h:X-Mailgun-Variables': JSON.stringify({test: "test"})
};
console.log('Data: ', data);
let result;
try {
const x = this.mailgunApi.messages.create(domain, data);
result = await x;
} catch (e) {
console.error('Failed sending email: ', e);
throw e;
}
return result;
I’m getting a 400 error back from the server and it is logging the following:
Failed sending email: [Error: BAD REQUEST] {
status: 400,
details: "'from' parameter is missing"
}
It looks like the form data isn’t being appended properly. After digging around for a while, I found a similar issue in the form-data github repo.
https://github.com/form-data/form-data/issues/478
So far I’ve tried upgrading form-data from 2.5.1 to 3.0.0, but still no luck.
It seems like in the previous version of mailgun-js, another library (popsicle) was used for managing the form data request parameters.
(On further digging, popsicle 1.4.0 just used form-data anyways.)
Since the mailgun-js 3.0.0 postMulti() uses the new keyword, it doesn’t look like I’ll be able to use popsicle the way it was used in the 2.0.6 release.
I’m going to try to revert to the previous version of mailgun-js in the meantime.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 15 (1 by maintainers)
Commits related to this issue
- deps(provider-email-mailgun): upgrade mailgun.js to 8.2.1 Fixes the following issue: - https://github.com/mailgun/mailgun.js/issues/92 — committed to nurulhudaapon/strapi by nurulhudaapon a year ago
This library is making it almost impossible to use. First of all the documentation within the mailgun app is obsolete. It’s using the older
mailgun-jsclient. Trying to use this client from nodejs runs into so many other errors. Finally got stuck with the above oneThe upgrade to the latest
8.2.1version fixed the issue.I’m getting this same problem in
mailgun.js@5.2.2I’ve been trying to access this API from mailgun, it seems the documentation is a bit misleading. when using https://api.mailgun.net/v3/xxxxx.domain/messages it seems that the body should be in a form of params for the API to recognize it.
@dereekb @ShankarSumanth I’m sorry about the issue. It’s been fixed in v3.1.1. Could you please try again and let me know if I can help you somehow? For now, I’m closing this one, please open a new one if you find something else. Thank you!
I contacted Mailgun and they said;
We are now using https://mailersend.com, even the dashboard is a lot faster and more modern.
I highly recommend switching, they also offer many packages that they maintain. In my case they had a seemless integration with Laravel. So it took literally no time to get up and running.
Still encounter the issue in version 8
Took less than 15 min to achieve the same result with formdata and axios. For anyone still facing this issue. The easiest way to mitigate,
My requirements are currently simple and I don’t want to be again in a situation where I have to spend a day to debug a library to fix this issue.