我正在尝试使用解析云代码发送电子邮件,解析javascript sdk和mailgun。这是我的云代码:
Parse.Cloud.define("sendEmail", {useMasterKey: true}, function(request,response){
var api = "xxxx";
var domain = "xxxx";
var mailgun = require('mailgun-js')({
apiKey: api,
domain: domain
});
var mail = {
from: request.params.email,
to: "someemail@email.com",
subject: request.params.name,
text: request.params.message
};
mailgun.messages().send(mail, function (error, body) {
if (error) {
inspect(error, 'mailgun sendError');
} else {
inspect(body, 'Successfully send email to "' + toEmail + '"');
}
});
});
这是我的客户代码:
Parse.initialize("app-id");
Parse.serverURL = 'example.com/parse';
var SendEmail= Parse.Object.extend("SendEmail");
var sendEmail= new SendEmail();
$("#someform").on("submit", function(e) {
e.preventDefault();
var data ={};
data.name = $("#name").val();
data.email = $("#email").val();
data.message = $("#message").val();
sendEmail.set("name", data.name);
sendEmail.set("email", data.email);
sendEmail.set("message", data.message);
console.log(data);
sendEmail.save(data, {
success:function(result){
console.log("success saved!");
Parse.Cloud.run('sendEmail', data).then(function(result) {
console.log("Success");
}, function(error){
console.error("Fail");
});
},
error: function(error){
console.error("something is wrong!");
}
});
});
保存在我的解析服务器中的数据,mailgun日志显示状态200并且电子邮件已成功发送但解析服务器每次都自动关闭,当我重新启动解析服务器时,日志显示“错误处理请求:ParseError {code:142 ,消息:'验证失败。' }”。我仍然可以通过删除useMasterKey来接收消息并保存数据但无法获取日志。我试图创建另一个新的解析服务器,它最终相同。有人可以指导我吗?