Hi,
I am migrating from Parse. I have there a trigger to invoke a function (sendEmail) through Cloud Code and then to send a request to Mailgun. The trigger is very simple:
// function to send emails via Mailgun
Parse.Cloud.define("sendMail", function(request, response) {
var mailgun = require('mailgun');
mailgun.initialize('example.com', 'key-example');
mailgun.sendEmail({
to: request.params.toEmail,
from: request.params.fromEmail,
subject: request.params.subject,
text: request.params.text
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
This function, I call it through iOS and Android frontends to send emails.
Now, I would like to add the same functionality in Backendless. I know that I have the Business Logic feature to do this. I noticed that JS is added recently, like Mark Piller said in the last videoconference that I joined recently.
In Backendless website I go to Business Logic, then to Custom Events, and I add a new one “sendEmail”. Then, I download it, and I have a zip with the structure. OK, I go then to sendEmail.js and edit it with:
Backendless.ServerCode.customEvent('sendMail', function(request, response) {
//add your code here
var mailgun = require('mailgun');
mailgun.initialize('example.com', 'key example');
mailgun.sendEmail({
to: request.params.toEmail,
from: request.params.fromEmail,
subject: request.params.subject,
text: request.params.text
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
}, true);
Please, could you confirm this code is right to upload it to Backendless?
After this, I read in the docs, that I have to deploy this code and upload to Backendless. The way is using Code Runner.
I see in the docs that I have Code Runner in the Backendless website in PHP and Java. But, my question is:
If I would like to deploy and edited .js file, I have to use a Code Runner utility, how? Because Code Runners are in Java and PHP.
Thanks.
King regards,
Jose