Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach a csv file to email using Mandrill?

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);
                  });
like image 470
user3527354 Avatar asked Feb 25 '17 00:02

user3527354


1 Answers

According to the documentation of the Mnadrill API, you need to encode the content in base64:

enter image description here

So, modify the following ...

"content": csv

...to:

"content": Buffer.from(csv).toString('base64')
like image 121
Nehal J Wani Avatar answered Sep 28 '22 12:09

Nehal J Wani