我正在Cloud Code
为Parse
设置Mailgun
以发送电子邮件。我已经成功完成了编写下面提到的Java Script代码
Parse.Cloud.define("SendEmail", function(request, response) {
var Mailgun = require('mailgun');
Mailgun.initialize('myDomainName', 'MyKey');
Mailgun.sendEmail({
to: request.object.get("to") ,
from: "info@sample.com",
subject: request.object.get("subject"),
text: request.object.get("text")
},{
success: function() {
response.success(request.params);
console.log("--email sent - success");
console.log(request.params);
},
error: function() {
console.log("--failed to send email - success");
console.error(request.params);
response.error("Uh oh, something went wrong");
}
});
});
但我不断收到以下错误
Error: TypeError: Cannot call method 'get' of undefined
at main.js:1:602 (Code: 141, Version: 1.2.20)
2014-08-20 02:05:03.725 PhotoAlert[475:60b] Error : Error Domain=Parse Code=141 "The operation couldn’t be completed. (Parse error 141.)" UserInfo=0x15ec5b90 {code=141, error=TypeError: Cannot call method 'get' of undefined
at main.js:1:602}
我正在焦急地寻找解决方案,因为我也是Parse / Mailgun和JS的新手。
此致
答案 0 :(得分:1)
我相信你所拥有的地方:
request.object.get("to")
应该是:
request.params.to
这适用于您传递给CloudCode函数的所有参数(to,subject和text)。
我自己也很新,我猜这个错误是说没有被称为“对象”的传递参数因此没有“获取”方法。