预先感谢您的回复。我编写了一些使用nodemailer 0.7.1的代码。它发送电子邮件并将pdf附加到电子邮件中。但是,.pdf 附件在编码时会自行损坏或截断或发生其他情况。我之所以说这是附件之前的文件(即我本地的文件)是512kb,而电子邮件中的附件只有1kb。
这是使用nodemailer的代码:
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] /cdn-cgi/l/email-protection",
to : "[email protected] /cdn-cgi/l/email-protection",
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 本身的数据就是这里的问题。
我将文件放在同一目录中以避免出现问题,甚至在当前目录的文件之前添加了“./”。我还将“文件路径”更改为“路径”,然后它根本没有发送任何附件。
我认为问题出在“附件”数组中。也许这些字段不正确,或者我需要添加更多信息。
如果有人可以告诉我是否需要流式传输或其他什么而不是我正在做的事情,如果需要的话如何流式传输文件,那就太好了!
var api_key = 'key-6b6987887a1aa9489958a5f280645f8b';
var domain = 'sandboxcd1a6d15d41541f38519af3f5ee93190.mailgun.org';
var mailgun = require('mailgun-js')({apiKey: api_key,domain:domain});
var path = require("path");
var filepath = path.join(__dirname, 'wacc.pdf');
var data = {
from: '[email protected] /cdn-cgi/l/email-protection',
to: '[email protected] /cdn-cgi/l/email-protection',
subject: 'Today Test',
text: 'Sending Test',
attachment: filepath
};
mailgun.messages().send(data, function (error, body) {
console.log(body);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)