Using Rules to email multiple users in drupal 7

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
vishalkhialani's picture

Goal: To send a email to a multiple users informing him that a product ( content type ) he bookmarked ( using Flag module) has been updated.


Few things to consider:


If many products get updated then one email with a summary should be sent out.


Each user using flag module selects his product of choice.

Where I am stuck using the Rules Module:

I can't seem to get the condition right in rules so that it executes the way I want it.


I am getting stuck at sending an email to users who had flagged/bookmarked the node to get notifications.


How can I get this right ?


Should I make my own module to make use of rules api ? If so do you have some suggestions ? or is there a way I can get this done .

Comments

^

Ayesh's picture

You will have to execute a Rules set on each user. VBO is the ideal module I suggest.
You can use a View with UID argument and Relationship to Flag so only flagged nodes return to View.
You will have to execute the Views remotely to check if the View return more than one result (if yes, jump to summary email template). Most likely that a combination of 3 Views and 2 flags

I don't know a direct way - just an idea :)

@Ayesh Thanks, currently I am

vishalkhialani's picture

@Ayesh

Thanks, currently I am trying to figure out what is the best way myself.

A simpler approach could be

marcoscano's picture

A simpler approach could be using module Rules Bonus Pack.

First create a view listing all the users that have flagged that particular product.

Then set a rule that triggers on "a node has been flagged", and execute the action "load user list from views". This will get you available to rules the list of users in order for you to perform the next actions.

The next thing is adding a Loop, which will loop through all the users you have just loaded. Inside the loop add the email action, to send to each user. In the case you need to customise your email depending on the user, perhaps the best option is to copy the "send email" code from the rules module into a custom module, and do the modifications you need directly in a custom action.

just realized that there is

marcoscano's picture

just realized that there is an even simpler approach, apparently on the latest version of rules/flag you have directly an option to "fetch all users who have flagged a node". This will avoid you having to create the view to load the users. I havent tested it directly, but it looks like you can add the loop directly after fetching the users with this built-in action

Hope it helps

bingo !

vishalkhialani's picture

@clanet

Thanks, It worked. Now I have another issue which I did not think of.

1) Say 10 nodes are updated . I don't want 10 emails to go to one user. Can I make it into a digest ? So one email says everything in it.

2) Also is there a way I can schedule the action to take place once a week instead of it sending it the moment the update takes place ?

Cheers,
Vishal

Yes you can do this

tassaf's picture

Yes you can do this easily..

Use elysia_cron to schedule a check in a specific time
do that process and send the result in one email

Funciona

jordiespuny's picture

hola!

lo acabo de usar! gracias Marcos!

Saludos

update

vishalkhialani's picture

so I making my own module I don't think rules can do it off the bat.

I used hook_rules_action_info() and now I am able to get each user who flagged the content.

How do I get the information of the node which was updated ?

node is not an entity is it ? How can I access the nodes details ?

Below is my code

#

<?php




/<em>
*
Implementation of the hook_rules_action_info()
*
*/
function
customvishal_rules_action_info()
{
$actions = array(
   
'customvishal_action_userdetail' => array(
       
'label' =>t('Custom function to send notifications'),
       
'group'=>t('Cusotm Code for sending notifications'),
       
'parameter'=> array(
        
'account'=> array(
            
'type'=>'user',
            
'label'=>t('Going to get user list'),
            
         ),  
        )
    ),
   
   
   
);

return
$actions;
 
}


/</
em>
*
The action function for the rules exampled hello world
*
*/
function
customvishal_action_userdetail($account)
{

 
drupal_set_message(t('This user #username! has flagged it',
          array(
'#username' => $account->mail)));

 
// how do I access the node now ?
}
?>

Conditional actions

sreekanth1201's picture

I want to update my registration profile with order id and status after check out.I know that conditional actions replace with Rules i drupal 7..I want to execute php code in rules like how we can do in conditional action..when i say add to cart the node is saving and asking for check out..i want to update that node after check out..please help...

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week