Ich möchte ein PDF-Dokument mit Hilfe von "nodemailer" und "node.js" anhängen, die einzigen Beispiele, die ich für Anhänge mit nodemailer finde, sind .txt-Dateien (here).Node.js und Nodemailer: Können wir PDF-Dokumente an E-Mails anhängen?
Weiß jemand, ob das Anhängen von PDF-Dokumenten mit nodemailer unterstützt wird?
Zunächst scheint es, dass ein PDF angehängt werden kann, aber die PDF-Datei, die durch die E-Mail ankommt, scheint beschädigt zu sein (siehe Bild).
Code: (Angepasst von Mahesh Antwort)
fs.readFile('/filePath/fileName.pdf', function (err, data) {
if (err) throw err;
var mailOptions = {
from: 'Test <[email protected]>', // sender address
to: 'toPersonName <[email protected]>', // list of receivers
subject: 'Attachment', // Subject line
text: 'Hello world attachment test', // plaintext body
html: '<b>Hello world attachment test HTML</b>', // html body
attachments: [
{
filename: 'fileName.pdf',
contentType: 'application/pdf'
}]
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
console.log(data);
});
Terminal-Antwort:
<Buffer 25 50 44 46 2d 31 2e 33 0a 25 c4 e5 f2 e5 eb a7 f3 a0 d0 c4 c6 0a 34 20 30 20 6f 62 6a 0a 3c 3c 20 2f 4c 65 6e 67 74 68 20 35 20 30 20 52 20 2f 46 69 ... >
Message sent: 250 2.0.0 OK 1443026036 hq8sm3016566pad.35 - gsmtp
AFAIK unterstützt alle Nicht-Text-Content-Typen – prasun