mailgun / mailgun.js

Javascript SDK for Mailgun
https://www.npmjs.com/package/mailgun.js
Apache License 2.0
519 stars 110 forks source link

Filename isn't respected for string attachments #387

Closed cprussin closed 9 months ago

cprussin commented 11 months ago

If I pass an attachment where the data is a string, the filename & contentType are ignored. For instance:

mg.messages.create("somedomain.com", {
    ...,
    attachment: {
        filename: 'my-cool-attachment.csv',
        data: 'check,this,stuff,out',
        contentType: 'text/csv'
    }
});

The issue appears to be caused by these lines which do not use the filename in any way.

I'm happy to put in a fix but I don't know enough about the form data stuff going on in this library and I know there's a lot of backward compatibility so I'd need some guidance on what the right fix is... I'm guessing we should wrap the string body in a Blob before passing to FormData so that we can append the filename.

There's probably some other stuff affected here too....

chidg commented 10 months ago

Ran into this issue. Wrapping the string in Buffer.from solved it.