我已经使用mLab将应用程序从parse.com迁移到heroku,除云代码外,一切正常。
我使用Mandrill从解析云代码发送电子邮件,该代码不能与heroku一起使用
这是我到目前为止所做的:
这是我的代码脚本:
Parse.Cloud.define("sendMail", function(request, response) {
var Mandrill = require('mandrill');
Mandrill.initialize('xxxxxx-xxxxx');
Mandrill.sendEmail({
message: {
text: "ffff",
subject: "hello",
from_email: "xxxxx@gmail.com",
from_name: "pqr",
to: [
{
email: "xxxxxxxxxx@gmail.com",
name: "trump"
}
]
},
async: true
},{
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
但在调用'sendMail'函数后,我收到此错误:
[错误]:功能无效。 (代码:141,版本:1.13.0)。 ================================== MailGun =============== ===========
Parse.Cloud.define('hello', function(req, res) {
var api_key = 'key-xxxxxxxxxxxxxx';
var domain = 'smtp.mailgun.org';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
var data = {
from: 'xxxxxxxald@gmail.com',
to: 'xxxxx8@gmail.com',
subject: 'Hello',
text: 'Testing some Mailgun awesomness!'
};
mailgun.messages().send(data, function (error, body) {
console.log(body);
});
//res.success(req.params.name);
});
答案 0 :(得分:0)
我遇到了与sendgrid类似的问题,但我终于找到了解决问题的方法。
我认为这些步骤可能会对您有所帮助,
错过一些括号或一些代码分隔符? (尝试重写main.js中的整个代码)
该应用实际上正在运行? (当您键入" heroku打开"在终端中您会收到默认消息?) - 如果不是,请检查步骤1.
如果以前不能正常工作,请回滚到安全版本并在heroku仪表板中添加附加组件而不是自己安装它们,然后下载git并对git进行任何更改然后再推送。
答案 1 :(得分:0)
下面我粘贴了在heroku解析应用程序上使用Mandrill工作的云代码main.js代码来发送密码恢复电子邮件。
在云代码main.js中:
var mandrill_key = process.env.MANDRILL_KEY;
var Mandrill = require('mandrill-api/mandrill');
var mandrill_client = new Mandrill.Mandrill(mandrill_key);
{
success: function(gameScore) {
//alert('New object created with objectId: ' + gameScore.id);
mandrill_client.messages.send(
{
message: {
html: "<p>Hello " + firstUser.get('fullname') + ",</p><p>We received your request to reset your password.</p><p>Your user name is <strong>" + firstUser.get('username') + "</strong>. Please <a href=\"http://test-sample-app.herokuapp.com/?#/account/reset/password/" + jsonct.ct + "\">click here</a> to create a new password. This link will expire in one hour after this mail was sent</p><p>If you need additional help, just let us know.</p><p>SampleCompany Support<br>customerservice@example.com</p><p>Copyright Sample Company, Inc. 2014-2017</p>",
subject: "Sample Company Name account recovery",
from_email: "customerservice@example.com",
from_name: "Sample Company Name",
to: [
{
email: firstUser.get('email'),
name: firstUser.get('fullname')
}
]
},
async: true
},
//Success
function(httpResponse) {
console.log(httpResponse);
//alert("Email sent!");
},
//Failure
function(httpResponse) {
console.error(httpResponse);
//alert("Uh oh, something went wrong");
});
},
error: function(gameScore, error) {
console.error(error.message);
//alert('Failed to create new object, with error code: ' + error.message);
},
useMasterKey: true
})