Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct mailgun JS library? #345

Open
pelicanenglw opened this issue Jan 31, 2023 · 12 comments
Open

Correct mailgun JS library? #345

pelicanenglw opened this issue Jan 31, 2023 · 12 comments

Comments

@pelicanenglw
Copy link

pelicanenglw commented Jan 31, 2023

I’m really confused…. The mailgun API docs were updated yesterday - Jan 30, 2023 and it still lists mailgun-js as the formally supported library. On the plus side it works but there are security issues with old dependencies.

This library does not appear to work. (See form-data issue #339 form-data error)

Does anyone have a working node example using this library?

@nosovk
Copy link

nosovk commented Feb 3, 2023

Nope, it seems that lib is abandoned.
But you can use mailgun API directly, check answers in #341

@pelicanenglw
Copy link
Author

Nope, it seems that lib is abandoned.
But you can use mailgun API directly, check answers in #341

Thanks, I was already started down that road. It seems like the path of least resistance. It would be nice if Mailgun released a real data API rather than a form post.

@olexandr-mazepa
Copy link
Collaborator

Hello @pelicanenglw @nosovk
This SDK is officially supported by Mailgun, and I can't agree that its package is abandoned or doesn't work.
Yeap there are some places in docs that mention the old mailgun-js package, but that package is outdated and has security issues.
Talking about the issue you mentioned, it definitely needs investigation but it mentions only nestjs framework and should not influent you if you need SDK in another environment.
I am happy to help if you will have any issues regarding usage.
Also, I would like to say that this is an open-source repository as well so feel free to create a PR if you see areas for improvement.

@nosovk
Copy link

nosovk commented Feb 23, 2023

Actually I don't see place where nestjs mentioned. Issues mentioned in chat are regarding running in Cloudflare workers, and regarding node18 native formdata (more issues in GitHub).
Actually pull requests in a lib is mostly hanging for more than year...
It doesn't look that lib is maintained, but the REST API is well documented, and there are no problems in using it directly.

@nosovk
Copy link

nosovk commented Feb 23, 2023

Found issue with NestJS, it's related to typescript import, not to NestJS

@olexandr-mazepa
Copy link
Collaborator

Okay let's go one by one:

  • The nestjs framework was mentioned in the first message of this thread.

This library does not appear to work. (See form-data issue #339 form-data error)

It may be related to typescript import but it is more likely something wrong with the way of importing the form-data package in the nestjs, just because importing into a simple TS app works fine.

  • Launch in the Cloudflare workers is an issue and needs to be investigated. It is true that last time I kinda don't have so much time to work on the issues. But taking into consideration your message in that issue thread the issue is more likely with form-data package than SDK.
  • Talking about Pull requests, a lot of them are irrelevant and just need to be closed.
  • Support for Node 18 Form data was added just a couple of hours ago and had a delay because of the Axios issue.
  • I may be wrong but I also can't say that number of issues is high compared to the weekly downloading number.
    It is totally fine to use REST API directly if you find it more convenient but please don't say the library is abandoned

@nosovk
Copy link

nosovk commented Feb 23, 2023

just for information - according to #341 (comment) this lib could work without FormData at all.

The same story with axios - it's not necessary to use it when we have undici, it's seems that accepting fetch instead of FormData could be good idea.

Unfortunately weekly downloading number not a sign of quality or support. It means that library used as a backbone in some popular dependencies, nothing more.

Regarding pulls - if they are irrelevant and should be closed - then why they exist? Isn't it a sign of not well maintained library?

In common I was able to fix my issue without lib (see comment attached) and now for me issue is not relevant.

Thanks for willing to support OSS, Mailgun is good product and I hope they will support maintaining good nodejs wrapper for their library.

@pelicanenglw
Copy link
Author

The old library mailgun-js works fine, other than the security issues. The new one mailgun.js, certainly does not work in my testing (vanilla JS not TS). Using the form post api works correctly and this is what I ended up implementing. In general people are still being directed to -js both in docs and in forum posts. So this leads to a lot of confusion. The new library not working for some just adds to it. In my case the objects were correctly serialized by the form-data library but I did not spend more time on why it was generating the error in mailgun.js. The quicker path was talking directly to the mailgun API.

@olexandr-mazepa
Copy link
Collaborator

@pelicanenglw Happy to hear that you've resolved the issue.
Could you add more details about the environment where the library didn't work for you, is it nodeJS or browser, which version, OS, etc? I am curious to reproduce/fix this case.
Also, in case you have links to places where you saw links to the old package, please share them with me.
I already know about a few of them from separate GitHub issues, but maybe you have seen other places.

@pelicanenglw
Copy link
Author

@olexandr-mazepa we were using mailgun.js on the backend - Node v14.21.1. I only tested in my local environment (MacOS 12.5.1). The previous mailgun-js worked without issue.

@olexandr-mazepa
Copy link
Collaborator

olexandr-mazepa commented Feb 24, 2023

@pelicanenglw
It becomes more interesting 😃
I've just checked emails sent on the node v14.21.1 on mac os v12.6.3 and the SDK works fine.
image
image

This is the code example I used:

const YOUR_DOMAIN_NAME = 'domain';
const formData = require('form-data');
const Mailgun = require('mailgun.js');
const clientData = require('../client-options.json');

const mailgun = new Mailgun(formData);
const mailgunClient = mailgun.client(clientData);

const mailgunData = {
  from: 'Excited User',
  to: ['email address'],
  subject: 'Hello',
  text: 'Testing some Mailgun awesomness!',
  html: '<h1>Testing some Mailgun awesomness!</h1>'
};

(async () => {
  try {
    const res = await mailgunClient.messages.create(YOUR_DOMAIN_NAME, mailgunData);
    console.log(res);
  } catch (error) {
    console.log('error----------->', error);
  }
})();

Are you see a difference from your code that you think may cost the issue?

@sourabh-pc
Copy link

The v8.0.6 gives me a "Module Not Found Error" because i'am importing it with require. Whilst this error when i hover on the require id, it displays the correct path dir to "/node_modules/mailgun.js/index.ts". I'am using Node v16.9.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants