5

I'm creating some CiviMail mailings using the API. Sometimes my mailings get created and scheduled, but when they execute, they are marked as "completed" but show as having Intended Recipients: 0 in the mailing report, even though the recipient group is correctly populated:

CiviMail mailing report

When I create the exact mailing manually through the GUI, I get the proper intended recipients and the email is sent.

The code I'm using can be found in my CiviMail Tools Drupal module that provides rules integration for CiviMail using the CiviCRM API.

So, I have a rule component set up that creates a CiviMail mailing when a node is published. If I execute or schedule (rules scheduler) the rule component manually, the mailing gets intended recipients. However, if the component is scheduled automatically by an event trigger, then the CiviMail mailing is created and scheduled, but has Intended Recipients: 0 as in the above screenshot.

Any idea what might cause this? Again, it only happens when Drupal schedules my rule component based on an event trigger. If I schedule it manually, it all works. Very strange and difficult to troubleshoot!

  • 1
    Recommend posting your code for mailing creation via API and your CivICRM version as part of the question. – Chris Burgess Jun 12 '15 at 2:44
  • Thanks @ChrisBurgess I've added a link to my code, found here: github.com/LunkRat/civimail_tools and added more background on the issue. – Link Swanson Jun 12 '15 at 15:06
  • @ChrisBurgess can you offer any insight into why my rules code works when I execute the component manually but not when scheduled via Rules Scheduler? Any suggestions welcome. Thank you. – Link Swanson Jun 15 '15 at 16:32
  • 1
    When you execute manually, you're logged in? And when Rules Scheduler is called from cron current user is anonymous? If so this behaviour is what you'd expect. Suggest checking current user when your linked code is called to see. – Chris Burgess Jun 15 '15 at 19:33
3

Check your user permissions. All too often something that works for me via the GUI, fails in the automation.

  • Thank you! I initially thought it was permissions. Is this symptom (0 intended recipients) possibly caused by lack of permissions? Which permissions should I look for? – Link Swanson Jun 12 '15 at 19:10
  • 2
    Permission to access the contacts as the user authenticated in the request where node is published. If the node is being published eg from node/add by a logged-in editor, their CiviCRM permissions should apply. If from a logged-out request, including cron when fired as anonymous user or a Drush execution without the -u (--user) flag, then expect no contact access. You can switch users easily enough (safely impersonating another user). – Chris Burgess Jun 12 '15 at 20:16
  • Thanks for the comments, it was helpful. You were correct that it was Rules Scheduler executing the component code without access to contacts. Cheers. – Link Swanson Jun 16 '15 at 16:44

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.