2015-12-30 73 views
0

我想通过使用Parse.com的JS云云,利用Sendgrid通过电子邮件发送文件。该文件存在,它查询它的权利,它只是不将其连接到电子邮件通过解析云模块通过电子邮件发送文件Sendgird

var theFile = object.get("file") 
var sendgrid = require("sendgrid"); 
sendgrid.initialize("***", "**"); 
var email = sendgrid.Email({to: ['[email protected]']}); 
email.setFrom('[email protected]'); 
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

好像你的'addFile'方法有错误的签名。请参阅[文档](https://github.com/sendgrid/sendgrid-nodejs#addfile);它只需要一个对象,而不是一个参数列表。 –

回答

0

到addFile】这个params是不正确的,试试这个:

email.addFile({ 
    filename: theFile.name(), 
    url: theFile.url() 
}); 
+0

我一直在这里解析文档。 https://github.com/elbuo8/sendgrid-parse我尝试了这种方法,但它无法识别parse.com中的url参数 –

+0

结果:TypeError:无法在Email.addFile(sendgrid)上调用未定义 的方法'url' .js:222:40) at e.query.find.success(main.js:19:15) at e。 (Parse.js:14:28224) 在ES(Parse.js:14:27156) 在envalue(Parse.js:14:26575) 在ES(Parse.js:14:27284) 在烯值(Parse.js:14:26575) at es(Parse.js:14:27284) at envalue(Parse.js:14:26575) at e。 (Parse.js:14:27228) –

0

让其他人都必须经过这个巨大的麻烦。 addFile()函数被同步调用并调用addFileFromBuffer(),这意味着如果您在添加文件后立即发送电子邮件,那么电子邮件将在创建附件之前发送。在addFile()的函数内调用sendEmail()。

var theFile = object.get("file") 
var sendgrid = require("sendgrid"); 
sendgrid.initialize("***", "**"); 
var email = sendgrid.Email({to: ['[email protected]']}); 
email.setFrom('[email protected]'); 
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); 
});