2014-07-26 97 views
0

之前編碼和從未使用過的Cloud Code的新手。無法使用Parse Cloud Code和Mandrill發送電子郵件

我需要發送確認電子郵件,當有人用我的網頁上的表單提交他們的電子郵件與解析雲代碼,但我不能得到它的工作。我正在使用Mandrill雲模塊發送電子郵件。

我的問題是 -

a)我是否正確調用雲功能? b)變化的唯一變量是個人電子郵件地址。我是否正確傳遞該變量?

示例代碼真的有幫助。

感謝

這裏是我的雲代碼:

Parse.Cloud.define("introEmail", function(request, response) { 
var Mandrill = require('mandrill'); 
Mandrill.initialize('*************'); 

mandrill.sendEmail({ 
message: { 
    text: "Hello!", 
    subject: "Thanks for Signing Up!", 
    from_email: "[email protected]", 
    from_name: "Chad", 
    to: [ 
    { 
     email: request.params.Address, 
     name: "" 
    } 
    ] 
}, 
async: true 
}, { 
success: function(httpResponse) { response.success("Email sent!"); }, 
error: function(httpResponse) { response.error("Uh oh, something went wrong"); } 
}); 
}); 

這裏是我的JS代碼:

$(".input-group-btn").click(function() { 
    console.log("Notify Me"); 

    var Address = $(".form-control").val(); 

    var Email = Parse.Object.extend("Email"); 
    var email = new Email(); 

    email.set("Address", Address); 

    console.log(Address); 

    email.save(null, { 
     success: function(email) { 
      console.log('New object created with objectId: ' + email.id); 
      Parse.Cloud.run(introEmail,Address) 

     }, 
     error: function(email, error) {    
      alert('Could not accept email address: ' + error.message); 
     } 
    }); 

}); 

回答

0

一)呼叫與Parse.Cloud.run()的雲功能,但是,你必須傳遞名稱,數據,選項。這些是'introEmail'(雲功能的名稱),變量是{Address:$(「。form-control」).val()}和成功/錯誤處理程序。

b)見一

Parse.Cloud.define("introEmail", function(request, response) { 
var mandrill = require("mandrill"); 
mandrill.initialize('*************'); 

    mandrill.sendEmail({ 
    message: { 
     text: "Hello!", 
     subject: "Thanks for Signing Up!", 
     from_email: "[email protected]", 
     from_name: "Test", 
     to: [ 
     { 
      email: request.params.Address, 
      name: "" 
     } 
     ] 
    }, 
    async: true 
    }, { 
    success: function(httpResponse) { response.success("Email sent!"); }, 
    error: function(httpResponse) { response.error("Uh oh, something went wrong"); } 
    }); 
}); 

這裏是JS的客戶端:

$(".input-group-btn").click(function() { 
    console.log("Notify Me"); 

    var Address = $(".form-control").val(); 

    var Email = Parse.Object.extend("Email"); 
    var email = new Email(); 

    email.set("Address", Address); 

    console.log(Address); 

    email.save(null, { 
     success: function(email) { 
     // Execute any logic that should take place after the object is saved. 
     console.log('New object created with objectId: ' + email.id); 
     // Invoke our cloud function, using the phone number in the text field 
     Parse.Cloud.run('introEmail', { 
      Address: $(".form-control").val() 
      }, { 
       // Success handler 
       success: function(message) { 
        alert('Success: ' + message); 
       }, 
       // Error handler 
       error: function(message) { 
        alert('Error: ' + message); 
       } 
      }); 
     } 
    }); 
}); 
相關問題