drupal-7drupal-rules

How to send an Email notification by day end using Rules with all the nodes published that day?


I am trying to achieve email notification . The condition is , it should go by end of the day with the current day published content list.

For the same I have tried couple of things using Rules, but stuck in between.

Any help?

I tried using rules, and I created a rule like so:

When I am trying to add second condition to check if the node is published within 24hrs, I am unable to achieve it. When I add strtotime("-1 day"), I get an error like:

Wrong date format. Specify the date in the format 2017-05-10 08:17:18.

I tried date('Y-m-d h:i:s',strtotime("-1 day")) but I did not succeed.

Now I am trying one more method to achieve it using Views Rules which is suggested in this answer to the question about 'How to create a Drupal rule to check (on cron) a date field and if passed set field "status" to "ended"?'.


Solution

  • Below is a blueprint of how I'd get this to work ...

    Step 1: Create a single eMail for each node that was published

    Step 2: Group all eMails in a single eMail

    Obviously, the previous step creates a single eMail for each node that was published in the last 24 hours. If you only have a few nodes that may not be a real issue to worry about. But if you have dozens (or more?) of such nodes then you might want to consider consolidating all such eMails in a single eMail, which contains (in its eMail body) the complete list of nodes.

    A possible solution to implement such consolidation, is similar to what is shown in the Rules example included in my answer to "How to concatenate all token values of a list in a single field within a Rules loop?". In your case, you could make it work like so:

    1. Add some new Rules variable that will be used later on as part of the eMail body, before the start of your loop. Say you name the variable nodes_list_var_for_email_body.
    2. Within your loop, for each iteration, prepend or append the value for each "list item" to that variable nodes_list_var_for_email_body.
    3. Move the Rules Action to send an eMail outside your loop, and after the loop completed. And finetune the details (configuration) of your (new) "send an eMail" Rules Action. When doing so, you'll be able to select the token for nodes_list_var_for_email_body to include anywhere in your eMail body.

    Step 3: Schedule the daily execution of your rule

    Use the Rules Once per Day to schedule the daily execution of your rule. Refer to my answer to "How to limit the execution of a rule for sending an email to only run once in a day?" for way more details about this module.

    VoilĂ , that's it ...