I have Views, Rules and Views Rules installed. I have created a View with a Rules display time as an unformatted list which brings in the email for every user on the site. I want to then go into Rules and have it email that list anytime a new node is created of the content type Announcement.

So the question is how do I get that list into Rules to email everyone on the list?

(You can see with the View and Rule I currently have it setup to just email the administrators due to the Role assignment. But I want to make that Rule use the View list I have created. Just using Roles currently to get it to work until I can find an answer to the list.)

View:

$view = new view();
$view->name = 'paradise_peninsula_mail_list';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Paradise Peninsula Mail List';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Paradise Peninsula Mail List';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  3 => '3',
  5 => '5',
  4 => '4',
);
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: User: E-mail */
$handler->display->display_options['fields']['mail']['id'] = 'mail';
$handler->display->display_options['fields']['mail']['table'] = 'users';
$handler->display->display_options['fields']['mail']['field'] = 'mail';
$handler->display->display_options['fields']['mail']['label'] = '';
$handler->display->display_options['fields']['mail']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['mail']['link_to_user'] = '0';
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: User: E-mail */
$handler->display->display_options['filters']['mail']['id'] = 'mail';
$handler->display->display_options['filters']['mail']['table'] = 'users';
$handler->display->display_options['filters']['mail']['field'] = 'mail';
$handler->display->display_options['filters']['mail']['operator'] = 'not_ends';
$handler->display->display_options['filters']['mail']['value'] = '@change.com';
/* Filter criterion: User: Roles */
$handler->display->display_options['filters']['rid']['id'] = 'rid';
$handler->display->display_options['filters']['rid']['table'] = 'users_roles';
$handler->display->display_options['filters']['rid']['field'] = 'rid';
$handler->display->display_options['filters']['rid']['value'] = array(
  3 => '3',
);

/* Display: Rules */
$handler = $view->new_display('views_rules', 'Rules', 'views_rules_1');
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['rules_variables'] = array(
  'mail' => array(
    'enabled' => 1,
    'rendered' => 1,
    'type' => 'list',
    'label' => 'User: E-mail',
    'name' => 'collected_user_email',
  ),
);

Rule:

{ "rules_new_content_email_notification" : {
    "LABEL" : "New Content Email Notification",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--announcements" : { "bundle" : "announcements" } },
    "DO" : [
      { "mail_to_users_of_role" : {
          "roles" : { "value" : { "3" : "3" } },
          "subject" : "Paradise Peninsula - [node:title]",
          "message" : "[node:body]",
          "from" : "[site:current-user]"
        }
      }
    ]
  }
}

Comments

ryanfc78’s picture

any thoughts on this?

zeezhao’s picture

Alternatively, you may want to try https://www.drupal.org/project/views_send which is already built for something like this.

ryanfc78’s picture

I installed and looked at this but seems a bit complicated and has several options I don't want members to have to deal with. Would prefer it just worked in the background when they added content of specific type. I would just like to be able to control the list in the background for the client.