user3527354
user3527354

Reputation: 586

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);
                  });

Upvotes: 5

Views: 2450

Answers (1)

Nehal J Wani
Nehal J Wani

Reputation: 16619

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')

Upvotes: 7

Related Questions