我正在使用长文本测试Sendgrid
:
我和那个伊索,那个小丑,那个皮埃罗没什么关系,只是像他们一样,只是在这件事上被抓住了。“
他决定放弃他对monastry的诉讼“。
然而,一旦我发送邮件,就会发现这样没有换行:
所以我的问题是我做错了什么?!
我的代码:
mymailer.sendTemplate = function (template_id, to, from, subject, keyReplacer, section, text, files, replyTo) {
var email = new sendgrid.Email(),
templateKey = templates[template_id];
email.subject = subject;
email.text = text;
email.setFilters({
"templates": {
"settings": {
"enable": 1,
"template_id": templateKey
}
}
});
email.smtpapi.isHtml = true;
email.smtpapi.header.sub = prepareSub(keyReplacer, section);
email.smtpapi.header.section = prepareSection(section);
email.files = prepareAttachement(files);
sendgrid.send(email);
};
function prepareSection(section) {
var finalObject = {};
if (section) {
_.forEach(section, function (value, key) {
var k = '%' + key + '%';
finalObject[k] = value;
})
}
return finalObject;
}
function prepareSub(keyReplacer, section) {
var finalObject = {};
if (keyReplacer) {
finalObject['firstname'] = keyReplacer;
_.forEach(section, function (value, key) {
finalObject[key] = [];
for (var i = 0; i < keyReplacer.length; i++) {
finalObject[key].push(value);
}
})
}
return finalObject;
}
function prepareAttachement(files) {
var finalArray = [];
if (files) {
var i = 0;
_.forEach(files, function (file) {
finalArray.push({
filename: file.file_name,
contentType: file.file_type,
cid: 'file-' + i,
content: fs.readFileSync(file.path)
});
i++;
});
}
return finalArray;
}