Azeem Akram
Azeem Akram

Reputation: 120

Send email through Mailgun using Parse

I am trying to setup Cloud Code in Parse for Mailgun to send emails. I have successfully done with writing the Java Script code mentioned below

Parse.Cloud.define("SendEmail", function(request, response) {

    var Mailgun = require('mailgun');
    Mailgun.initialize('myDomainName', 'MyKey');

    Mailgun.sendEmail({
            to: request.object.get("to") , 
            from: "[email protected]",
            subject: request.object.get("subject"),
            text: request.object.get("text")
        },{
        success: function() {
            response.success(request.params);
            console.log("--email sent - success");
            console.log(request.params);
        },
        error: function() {

            console.log("--failed to send email - success");
            console.error(request.params);
            response.error("Uh oh, something went wrong");
        }
    }); 


});

But I am continuously getting the following error

Error: TypeError: Cannot call method 'get' of undefined
    at main.js:1:602 (Code: 141, Version: 1.2.20)
2014-08-20 02:05:03.725 PhotoAlert[475:60b] Error : Error Domain=Parse Code=141 "The operation couldn’t be completed. (Parse error 141.)" UserInfo=0x15ec5b90 {code=141, error=TypeError: Cannot call method 'get' of undefined
    at main.js:1:602}

I am anxiously looking for solution as I am new for Parse/Mailgun and JS too.

Regards

Upvotes: 1

Views: 1710

Answers (1)

petek157
petek157

Reputation: 28

I believe that where you have:

request.object.get("to")

It should be:

request.params.to

And that goes for all of the parameters that you are passing into the CloudCode Function (to, subject and text).

Being very new to this myself, Im guessing that the error is saying that the is no argument being passed in called "object" therefor there is no "get" method for it.

Upvotes: 1

Related Questions