I have a working mailgun server in my parse cloudcode for an iOS app. I have set up a series of emails to be triggered by status changes in the database. I have now set up a welcome email that was formerly hard coded into the app. I have it set up as an afterSave however during the app the user is saved more than once, causing the welcome to be triggered. Is there a way I can only send this out once, or do I have to make it specific to a new user registering in the function if that is possible. Thanks.
Parse.Cloud.afterSave(Parse.User, function(request) {
console.log("aftersave fired");
if(!request.user.existed()){
var email = "Hello and welcome";
var subject = "Welcome to W!";
var recipient = request.user.get("email");
console.log(recipient);
Mailgun.sendEmail({
to: "@gmail.com",
from: "@gmail.com",
subject: subject,
text: email
}, {
success: function(httpResponse) {
response.success();
},
error: function(httpResponse) {
response.success();
}
});
}
});