1
votes

CONTEXT:

I am using Parse.com as the backend for my web application. I want to send myself an email when a new user has signed up (i.e., a new record is saved to the 'User' table). I am using the SendGrid Module for Parse.

PROBLEM:

The email does not send. I neither receive a success nor error response. Log files print "Step 2" but not "Step 3" (see below).

Also, I am not sure if "mySendGridFunction" refers to anything and needs to be changed.

CODE:

Parse.Cloud.afterSave(Parse.User, function(request) { // Indicate Function Start console.log("**********************************"); console.log("** New User Email Notification ***"); console.log("**********************************");

// For New Users Only
if(!(request.object.existed())){
    // New User Identified
    console.log("New user identified");

    // Initialize SendGrid Module
    var sendgrid = require("sendgrid");
    sendgrid.initialize("myUsername", "myPassword");
    console.log("Step 2");

    // Send Email
    Parse.Cloud.define("mySendGridFunction", function(request, response) {
        console.log("Step 3");
        sendgrid.sendEmail({
            to: "[email protected]",
            from: "[email protected]",
            //from: "[email protected]",
            subject: "Notification: New User",
            text: "A new user has just signed up."
        }, {
            success: function(httpResponse) {
                console.log("User Notification email being sent");
                console.log("HTTP Response: " + httpResponse);
                response.success("User Notification email successfully sent");
            },
            error: function(httpResponse) {
                console.log("There was an error sending the User Notification email");
                console.error("HTTP Response: " + httpResponse);
                response.error("There was an error sending the User Notification email");
            }
        });
    });
}

});

1

1 Answers

1
votes

Alright, things are working! For those of you with a similar problem, I just removed the following line (and fixed closing brackets):

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

I think this is only needed if you want to call a function that uses SendGrid.