2

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();
}
});
}
});
Jack Dee
  • 21
  • 2

1 Answers1

0

You can do something as simple as set a flag in a new column on the User class which indicates that they have been welcomed. When the user is saved, check that flag and decide wether to send or not (and update the flag).

Wain
  • 118,658
  • 15
  • 128
  • 151