我正在尝试使用Parse.com的JS云云通过电子邮件发送文件,利用Sendgrid。该文件存在,它正确查询,它只是没有将它附加到电子邮件
var theFile = object.get("file")
var sendgrid = require("sendgrid");
sendgrid.initialize("***", "**");
var email = sendgrid.Email({to: ['pat.doyle95@gmail.com']});
email.setFrom('guy@email.com');
email.setSubject('Payroll');
email.setText("This is the payroll file for yesterday \n \n" + theFile.url())
console.log(theFile)
email.addFile(theFile.name(), theFile).then(function(e) {
console.log("In file add");
console.log(e);
console.log("this is filename " + theFile.name());
});
sendgrid.sendEmail(email);
该文件存在,它也显示在我收到的电子邮件中。虽然我仍然可以通过URL获取文件,但我想将其附加到电子邮件中。
答案 0 :(得分:0)
addFile的参数不正确,试试这个:
email.addFile({
filename: theFile.name(),
url: theFile.url()
});
答案 1 :(得分:0)
所以没有其他人必须经历这个巨大的麻烦。 addFile()函数被同步调用并调用addFileFromBuffer(),这意味着如果您在添加文件后立即发送电子邮件,则电子邮件将在创建附件之前发送。在addFile()函数内调用sendEmail()。
var theFile = object.get("file")
var sendgrid = require("sendgrid");
sendgrid.initialize("***", "**");
var email = sendgrid.Email({to: ['pat.doyle95@gmail.com']});
email.setFrom('guy@email.com');
email.setSubject('Payroll');
email.setText("This is the payroll file for yesterday \n \n" + theFile.url())
console.log(theFile)
email.addFile(theFile.name(), theFile).then(function(e) {
console.log("In file add");
console.log(e);
console.log("this is filename " + theFile.name());
sendgrid.sendEmail(email);
});