2015-12-30 72 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); 
});