formData property 'name' undefined when sending an email
See original GitHub issueHello! I’ve just landed on a project that was using mailgun-js
and I’m having some trouble migrating to mailgun.js
package. The issue seems to be with form-data
package. The client initialization is correct and when running the function return await mailgun.messages.create(mailgunDomain, messageData)
the node app crashes with the following error
Request error! TypeError : Cannot read property 'name' of undefined
TypeError: Cannot read property 'name' of undefined
at FormData._getContentDisposition (/Users/PERE/Developer/marketplace-mary-services/node_modules/form-data/lib/form_data.js:227:40)
[...]
I see that form-data
expects a value that I think mailgun.js
should provide, maybe?
Here is my initialization
const Mailgun = require('mailgun.js')
const formData = require('form-data')
const mailgun = new Mailgun(formData)
const { MAILGUN_KEY, MAILGUN_HOST } = process.env
const mg = mailgun.client({
username: 'api',
key: MAILGUN_KEY,
url: MAILGUN_HOST
})
And the packages installed are the following in package.json
"form-data": "^4.0.0",
"mailgun.js": "^5.2.2",
What am I missing here?
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
TypeError: Cannot read property 'name' of undefined #336
What I noticed is that the issue comes up if any of the properties that you are setting on the form data has...
Read more >TypeError: Cannot read property 'name' of null NodeJs
This issue arises because in the formData key of requestPromise method you do not need to actually pass formData but an object ...
Read more >Cannot read property 'name' of undefined while using form ...
I am using `node-fetch` and in my call I am using `form-data` my code looks something ... TypeError: Cannot read property 'name' of...
Read more >Forms in HTML documents - W3C
A control's "control name" is given by its name attribute. The scope of the name attribute for a control within a FORM element...
Read more >I keep on having an issue of "TypeError: Cannot read property ...
I keep on having an issue of "TypeError: Cannot read property 'Email' of undefined" when trying to submit HTML form data to my...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It happens because the SDK handles property with the name ‘file’ as a file description. Here is a block of code that does that. https://github.com/mailgun/mailgun.js/blob/9d56b32d3d5f4fc7903dcdb368e338dc7b1a694e/lib/formDataBuilder.ts#L17-L21
I will change this behavior and publish the fix soon. Until I do that, as a temporary solution you can simply remove this property from the message data.
If I am not mistaking template is already compiled to HTML after these lines https://github.com/pmontp19/mailgun-example/blob/57e1c6c30a1960e44c917ad070917103eba34b59/index.js#L17-L18 so it looks like you don’t need the filename anymore in message data.
I’m still having this problem…and i’m not passing a
file
property.