mailgun / mailgun-js-boland

A simple Node.js helper module for Mailgun API.
http://bojand.github.io/mailgun-js
MIT License
894 stars 122 forks source link

Error: 'from' parameter is missing with CSV file attachment #245

Open Jilson opened 5 years ago

Jilson commented 5 years ago

1) What version of the module is the issue happening on? Does the issue happen on latest version? yes 2) What platform and Node.js version? (For example Node.js 6.9.1 on Mac OS X) Node 12.6.0 on Windows 10

I am totally stumped by an error I am receiving while sending an attachment. I have a function I run after generating a csv file from a number of API calls which sends that file as an attachment.

The function is simple, just takes the attachment filepath and text of the message

const sendEmail = (attachment, text) => {

    let data = {
        from,
        to,
        subject,
        text,
        attachment
    }

    mailgun.messages().send(data, (error, body) => {
        if(error) {
            console.log(error);
        } else {
            console.log(body);
            console.log('email sent')
        }
    });
}

When this function runs I have an error

Error: 'from' parameter is missing at IncomingMessage. (C:\Users\jwils\Code\sycle-reporting\node_modules\mailgun-js\lib\request.js:327:17) at IncomingMessage.emit (events.js:208:15) at endReadableNT (_stream_readable.js:1154:12) at processTicksAndRejections (internal/process/task_queues.js:77:11) { statusCode: 400 }

I am defining the from value in another variable, and the function works perfectly fine without an attachment. Once I try and send this file I receive the 'from" parameter missing, even though that isn't a missing parameter.

I have been able to send a file with this function under different circumstances, but when I do get this error there is no way of identifying the actual cause from the error message.

Are there any insights into sending csv files? I tried using the mailgun.Attachment class with no success either. I am totally stumped, and don't know where to move from here.

I have been able to send a blank .txt file, but the csv's seem to fail.

I appreciate any information into this specific error message.

Thank you, Julian

Jilson commented 5 years ago

I determined the error is actually that the attachment file did not exist at the time of the email sending. I had a race condition in my csv generation which caused the email to fail to send as the attachment was still writing to disk when it tried to send the email.

Ideally this error message would mention the actual missing parameter.

jankney2 commented 4 years ago

Thanks for this explanation @Jilson. I agree that the error message is misleading