簡體   English   中英

帶有Parse.com雲代碼和SendGrid的電子郵件通知

[英]Email Notification with Parse.com Cloud Code and SendGrid

背景:

我正在使用Parse.com作為Web應用程序的后端。 我想在新用戶注冊后向自己發送電子郵件(即,新記錄已保存到“用戶”表中)。 我正在使用SendGrid模塊進行解析。

問題:

電子郵件不發送。 我既未收到成功也未收到錯誤響應。 日志文件打印“步驟2”,但不打印“步驟3”(請參見下文)。

另外,我不確定“ mySendGridFunction”是否指向任何內容,是否需要更改。

碼:

Parse.Cloud.afterSave(Parse.User,function(request){//指示函數啟動console.log(“ ***************************** *********“); console.log(” **新用戶電子郵件通知***“); console.log(” **************** ******************“);

 // 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"); } }); }); } 

});

好了,一切正常! 對於那些有類似問題的人,我只刪除了以下行(並固定了右括號):

    Parse.Cloud.define("mySendGridFunction", function(request, response) {

我認為這僅在您要調用使用SendGrid的函數時才需要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM