I have a csv string that I am trying to send to as an attachment in an email but the content is coming out as gibberish. This is a node script. Any ideas?
// csv is a csv string
var message = {
"html": msg,
"subject": 'Test CSV Attachment',
"from_email": from,
"from_name": "Tester",
"to": [{
"email": email
}],
"headers": {
"Reply-To": email
},
"attachments": [{
"type": 'text/csv',
"name": filename,
"content": csv
}],
};
mandrill_client.messages.send({"message": message}, function(result) {
console.log('result NOTIFICATION! ', result);
});
According to the documentation of the Mnadrill API, you need to encode the content in base64:
So, modify the following ...
"content": csv
...to:
"content": Buffer.from(csv).toString('base64')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With