how to use back4app to send email with mailgun

387 views
Skip to first unread message

androm...@gmail.com

unread,
Feb 27, 2017, 6:57:40 PM2/27/17
to back{4}app
Hi i fail to use back4app with mailgun. so i just uploaded the cloud code

Parse.Cloud.define("sendEmail", function(request,response){
       
var api = "apikey";
       
var domain = "mydoamin";
       
var mailgun = require('mailgun-js')({
        apiKey
: api,
        domain
: domain
   
});
   
   
var mail = {
       
from: "nor...@email.com",
        to
: "so...@email.com",
        subject
: "title",
        text
: "message"
   
};

    mailgun
.messages().send(mail, function (error, body) {
       
if (error) {
            inspect
(error, 'mailgun sendError');
       
} else {
            inspect
(body, 'Successfully send email to "' + toEmail + '"');
       
}
   
});

});

I am using javascript sdk at client side

        Parse.initialize("appid", "key");
Parse.serverURL = 'what should i put for this?'

var SendEmail= Parse.Object.extend("SendEmail");
var sendEmail= new SendEmail();
$("#form").on("submit", function(e) {
e.preventDefault();

var data ={};
data.name = $("#name").val();
data.email = $("#email").val();
data.message = $("#message").val();
emailObjectCapture.set("name", data.name);
emailObjectCapture.set("email", data.email);
emailObjectCapture.set("message", data.message);
   
                         app.post('/sendEmail', function (req, res) {
Parse.Cloud.run('sendEmail', req.body).then(
function () {
console.log('Cloud Code Function called');
return res.send(200);
},
function (error) {
console.log("CLoud Code Function Called Fail");
return res.status(400).send(error.message);
});
});



This is not working and I got "app is not defined" error on client side. Am i right placing /sendEmail after app.post
Can't i just run Parse.Cloud.run without app.post?

i am using webhosting nodejs web app using cloud code example, since you guys don't have any vanilla javascript sample.
I am quite confuse because i never use app.post for parse, I just use Parse.Cloud.run

and do i need to use javascriptKey? or masterKey:true?
I am new to javascript and parse. Can you point me to right direction?

casag...@back4app.com

unread,
Mar 1, 2017, 9:15:57 AM3/1/17
to back{4}app
Hello,

Add this in Parse.serverURL = 'https://parseapi.back4app.com';

Also, you can use Parse.Cloud.Run if you are calling a function defined on your cloud code. Please check our Cloud Code Documentation http://docs.back4app.com/docs/integrations/

Best!
Reply all
Reply to author
Forward
0 new messages