无法发送包含Parse Cloud Code和Mandrill的电子邮件

时间:2014-07-26 18:35:35

标签: javascript jquery parse-platform mandrill

新编码,之前从未使用过Cloud Code。

当有人使用Parse Cloud Code在我的网页上以表格形式提交电子邮件时,我需要发送一封确认电子邮件,但我无法让它发挥作用。我使用Mandrill Cloud Module发送电子邮件。

我的问题是 -

a)我是否正确调用云功能? b)唯一变化的变量是人员电子邮件地址。我正确地传递了这个变量吗?

示例代码确实会有所帮助。

由于

这是我的Cloud Code:

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: "Test@Test.com",
  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);
        }
    });

});

1 个答案:

答案 0 :(得分:1)

a)使用Parse.Cloud.run()调用Cloud函数,但是,您必须传递名称,数据和选项。这些是' 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: "Test@Test.com",
      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);
                }
            });
        }
    });
});