背景:
我使用Parse.com作为我的Web应用程序的后端。我想在新用户注册时向自己发送电子邮件(即,新记录保存到“用户”表中)。我正在使用SendGrid模块进行解析。
问题:
电子邮件不发送。我既没有成功也没有错误回应。日志文件打印"步骤2"但不是"步骤3" (见下文)。
另外,我不确定" mySendGridFunction"是指任何东西,需要改变。
CODE:
Parse.Cloud.afterSave(Parse.User,function(request){ //表示功能开始 的console.log(" **********************************&#34); console.log(" **新用户电子邮件通知***"); 的console.log(" **********************************&#34);
// For New Users Only if(!(request.object.existed())){ // New User Identified console.log("New user identified"); // Initialize SendGrid Module var sendgrid = require("sendgrid"); sendgrid.initialize("myUsername", "myPassword"); console.log("Step 2"); // Send Email Parse.Cloud.define("mySendGridFunction", function(request, response) { console.log("Step 3"); sendgrid.sendEmail({ to: "me@mydomain.com", from: "sendgrid@parse.com", //from: "sendgrid@cloudcode.com", subject: "Notification: New User", text: "A new user has just signed up." }, { success: function(httpResponse) { console.log("User Notification email being sent"); console.log("HTTP Response: " + httpResponse); response.success("User Notification email successfully sent"); }, error: function(httpResponse) { console.log("There was an error sending the User Notification email"); console.error("HTTP Response: " + httpResponse); response.error("There was an error sending the User Notification email"); } }); }); }
});
答案 0 :(得分:1)
好的,事情正在发挥作用!对于那些有类似问题的人,我刚刚删除了以下行(并修复了右括号):
Parse.Cloud.define("mySendGridFunction", function(request, response) {
我认为只有在想要调用使用SendGrid的函数时才需要这样做。