如何使用 Mandrill 将 csv 文件附加到电子邮件?
How to attach a csv file to email using Mandrill?
我有一个 csv 字符串,我正尝试将其作为电子邮件附件发送至该字符串,但内容显示为乱码。这是一个节点脚本。有什么想法吗?
// 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);
});
根据Mnadrill的documentationAPI,需要对内容进行base64编码:
所以,修改以下...
"content": csv
...至:
"content": Buffer.from(csv).toString('base64')
我有一个 csv 字符串,我正尝试将其作为电子邮件附件发送至该字符串,但内容显示为乱码。这是一个节点脚本。有什么想法吗?
// 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);
});
根据Mnadrill的documentationAPI,需要对内容进行base64编码:
所以,修改以下...
"content": csv
...至:
"content": Buffer.from(csv).toString('base64')