我需要在特定交易后从Parse云代码向用户发送电子邮件。当我尝试使用以下代码时,它无法正常工作并发出如下错误:
[Error]: TypeError: object is not a function
at main.js:9:17 (Code: 141, Version: 1.12.0)
nil
这是云代码:
Parse.Cloud.define("mailSend", function(request, response) {
// using SendGrid's Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
var sendgrid = require("sendgrid")("SENDGRID_APIKEY");
var email = new sendgrid.Email();
email.addTo("test@sendgrid.com");
email.setFrom("you@youremail.com");
email.setSubject("Sending with SendGrid is Fun");
email.setHtml("and easy to do anywhere, even with Node.js");
sendgrid.send(email);
});
这里是Swift代码,用于调用云代码函数mailSend:
PFCloud.callFunctionInBackground("mailSend", withParameters: nil) { (response: AnyObject?, error: NSError?) in
}