1

I am trying to send custom welcome emails to custom user groups but Sprout email is attempting to send the notification before the user group is created which means the email isn’t sending. The log just outputs that the user doesn't belong to any user group.

Note: We are using a custom plugin to create the user and trigger a set your password email which could be the problem, is there a way to hook into sprout email so we can trigger the send from our plugin?

4
  • What event are you using as a trigger? – Ben Parizek Jun 24 '16 at 1:43
  • @BenParizek we are using "When a new user is created" and just specifying that it belongs to a specific user group. If I check "all" then it sends, but if I specify a particular group it doesn't. – Fox Jun 24 '16 at 2:01
  • This may be a bug or something else at play. I've answered the how to send a notification programmatically below, which may help if your situation is a bit more complex and you need to manually manage when the notification is triggered in your workflow. I'll add the question of why this doesn't work via the event to our list to look into and see if we can recreate it locally. – Ben Parizek Jun 24 '16 at 2:39
  • Awesome thanks! We'll give your suggestion below a whirl and update with the outcome! – Fox Jun 24 '16 at 2:44
1

You can programmatically trigger a notification email using the Sprout Email service layer. Notification Emails are sent via the SproutEmail_DefaultMailerService using the sendNotification() method:

craft()->sproutEmail_defaultMailer->sendNotification($campaign, $object);
  • $campaign needs to be a SproutEmail_CampaignModel
  • $object, in your case, would be the Craft UserModel (and more generally is any object that you want to make available to your email templates
2
  • Will this attempt to send multiple emails if we set the trigger as "When a new user is created" ? – Fox Jun 24 '16 at 2:22
  • Options are checked when an event is triggered, and if they pass, then a notification is sent. This method just sends the notification directly, and won't check any of your options - assuming you are using it somewhere in your code where you know that the conditions you want to meet are valid. – Ben Parizek Jun 24 '16 at 2:36
1

I don't think this is a bug. If you are saying that you are using a custom plugin on creating a user you will have to define an on onSaveUser event after the save user script.

E.g.

craft()->users->onSaveUser(new Event($this, array(
    'user'      => $user,
    'isNewUser' => $isNewUser
)));

Sprout Email uses Craft events to trigger the notification.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.