ご回答いただきありがとうございます。私はnodemailer 0.7.1を使用するいくつかのコードを書いています。それは電子メールを送信し、電子メールにpdfを添付します。ただし、.pdf添付ファイルは、エンコードや切り捨てなどの際に壊れてしまいます。私がこれを言うのは、添付ファイル(すなわち、私がローカルに持っているもの)が512kbで、電子メールの添付ファイルが1kbだけであるという理由です。PDF添付ファイルNodeMailer
これはnodemailerを使用するコードです:私はブラウザとしてGoogleのクロムを使用していますが、無駄に他のブラウザで試してみました
var nodemailer = require("nodemailer");
var util = require("./util");
var env = require('./environment');
var smtpTransport = nodemailer.createTransport("SMTP",{
service: env.service,
auth: {
user: env.user,
pass: env.password
}
});
exports.sendAttachment = function(info, callback, debug) {
util.validatInput(info, ["body"] , function(err, info){
if(err){
util.errPrint(err, "serverUtil/nodemailer.sendAttachment", 1, function(message){callback(err);});
}else {
var mailOptions={
from : "[email protected]",
to : "[email protected]",
subject : "Application from " + info.userEmail,
text : info.body,
attachments: [
{
fileName: 'file.pdf', //This needs to be the link to the form, or the actual form
filePath: 'file.pdf',
contentType: "application/pdf"
}
]
}
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
callback(err);
}
else{
console.log("Message sent: " + response.message);
callback({msg: "form sent"});
}
});
}
})
}
。明らかに、ブラウザ自体は、pdf自体のデータがここでの問題であるため、これと何ら関係がありません。
私は問題を避けるためにファイルを同じディレクトリに置き、現在のディレクトリのファイルよりも前に './'しました。私も 'filepath'を 'path'に変更してから、添付ファイルを一切送信しませんでした。
問題は「添付ファイル」の配列にあると思います。おそらく、フィールドが正しくないか、いくつかの情報を追加する必要があります。
私がやっていることではなくストリームにする必要があるかどうか誰にでも分かります。