我正在使用 NodeJs 发送带有附件 pdf 的电子邮件(通过 aws ses)。目前我正在尝试在 pdf 附件中添加 html 内容。当我收到附件 pdf 时,我无法打开 pdf 文件。我收到文件已损坏的错误。为了您的信息,我在这里添加了代码。如果我在此配置中遗漏任何内容,请告诉我
var message = '<html><body ><div style="margin: auto; width: 96%; border: 6px solid black; vertical-align:middle; text-align:center;height:auto"><img style="width: 204px; height: 128px;" src="image.png" /></div></body></html>';
var ses_mail = "From: 'Email' <" + email + ">\n";
ses_mail = ses_mail + "To: " + email + "\n";
ses_mail = ses_mail + "Subject: Subject Email\n";
ses_mail = ses_mail + "MIME-Version: 1.0\n";
ses_mail = ses_mail + "Content-Type: multipart/mixed; boundary=\"NextPart\"\n\n";
ses_mail = ses_mail + "--NextPart\n";
ses_mail = ses_mail + "Content-Type: text/html; charset=us-ascii\n\n";
ses_mail = ses_mail + message+"\n";
ses_mail = ses_mail + "--NextPart\n";
ses_mail = ses_mail + "Content-Type: application/pdf;\n";
ses_mail = ses_mail + "Content-Disposition: attachment; filename=\"attachment.pdf\"\n\n";
ses_mail = ses_mail + "Content-Transfer-Encoding: utf-8\n\n"
ses_mail = ses_mail + message + "\n";
ses_mail = ses_mail + "--NextPart--";
var params = {
RawMessage: { Data: new Buffer(ses_mail)},
Destinations: [ email ],
Source: "'AWS Tutorial Series' <" + email + ">'"
};
ses.sendRawEmail(params, function(err, data) {
if(err) {
console.log('failed');
}
else {
console.log('success');
}
});
});