Answers.Body: <p>I'm assuming what you have is a bunch of Drupal users that you are segmenting using Drupal field values.</p>
  
  <p>Step 1 Go here civicrm/admin/synchUser?reset=1 and make sure all your Drupal users are in CiviCRM.</p>
  
  <p>Step 2. Create a custom field for an individual. Make it Yes/No. Call it My Group or whatever. Make it searchable.</p>
  
  <p>Step 3. Make sure that you have the custom field group added to the database config in settings.php /civicrm/admin/setting/uf?reset=1 so you can use it in Drupal Views.</p>
  
  <p>Step 4. Create a view of CiviCRM contacts. Use a Drupal UID relationship so you can filter them into the group you want. Add the custom field you created in Step 2 to the view. Add a VBO filed. Modify the Entity value of the custom field. Bulk edit the custom field and set it to 1.</p>
  
  <p>Step 5. Go to CiviCRM and search for contacts with the custom field set to yes. Add them to a new Mailing Group.</p>
  
  <p>So you could have this as a smart group. You users just have to use VBO to add in the custom field value to update the smart group.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-08T15:59:05.530Z
Answers.Text: Thank you Tony : seems clever and smart ! Just one missing step : how would you automatically unflag the custom field afterwards (in order to use the same smart Group for other mailings) ?
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T09:31:13.197Z
Answers.Text: Maybe dont do that....What you could do is have a custom field for each mailing group in CiviCRM - so checking/unchecking them in VBO dynamically changes membership of each smart group....
Answers.UserDisplayName: Tony Horrocks
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-10T10:26:41.590Z
Answers.Text: I have to think about it
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-10T10:35:44.030Z
Answers.Text: I have an other concern : when I create a new custom field (Yes/No, searchable), it does not appear in the VBO config Token List, while all other existing custom fields are listed. Any idea to fix that ?
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-11T12:39:52.030Z
Answers.Text: Check it's in a custom field group that you added into your settings.php file - CiviCRM CMS integration etc etc. Also, does it have to be added in as a field in the view before you can access it?
Answers.UserDisplayName: Tony Horrocks
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-11T13:27:57.573Z
Answers.Text: All the other custom fields of the same group appear (this confirm that the pertainig table is included in the settings) + they are displayed in the list even thouh not included as View fields (just 2 or 3 of those are included in the View).
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-11T14:17:54.493Z
Answers.Text: Moreover, this custom field group contains 16 custom fields, including this last created : all the 15 others are displayed in the VBO list. I check your answer + I have just openned a new post on this subject : https://civicrm.stackexchange.com/questions/27297/views-bulk-operation-vbo-config-list-does-not-display-a-custom-field
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-08T11:43:17.123Z
Answers.LastActivityDate: 2018-11-08T12:05:15.650Z
Answers.LastEditDate: 2018-11-08T12:05:15.650Z
Answers.UserDisplayName: Tony Horrocks
Answers.Body: <p>You can create mailing jobs and execute them programmatically.</p>
  
  <p>Process:</p>
  
  <ol>
  <li>Create a mailing</li>
  <li>Create mailing job through code:</li>
  <li><code>$new_job = new CRM_Mailing_BAO_MailingJob();
      $params = array(
        'mailing_id' =&gt; MAILING_ID,
        'status' =&gt; 'Scheduled',
        'scheduled_date' =&gt; date('YmdHis'),
        'is_test' =&gt; 0,
      );
   $new_job-&gt;create($params);// Save job in database</code></li>
  <li>Execute mailing job through code:</li>
  <li><code>CRM_Mailing_BAO_MailingJob::runJobs();
   CRM_Mailing_BAO_MailingJob::runJobs_post();</code></li>
  </ol>
  
  <p>Hope that will lead you towards your goal.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-08T10:56:35.140Z
Answers.Text: Thank you Hassan for your input ; I am not a programmer, but this may be useful. But my concern is about transfering my list of selected contacts from Drupal Views to a mailing list.
Answers.UserDisplayName: Jacques-Marie Moranne
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-08T16:35:48.927Z
Answers.Text: Sorry to talk in programming sense again, but i could think of doing this using PHP sessions. Through session in views as Views PHP field you can set session with variable containing info of selected contacts and use that session when creating mailing list. You would need this module for using php in views. https://www.drupal.org/project/views_php
Answers.UserDisplayName: Hassan Farooq
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-07T20:16:34.450Z
Answers.LastActivityDate: 2018-11-07T20:16:34.450Z
Answers.UserDisplayName: Hassan Farooq
Body: <p>Drupal 7.60, Civicrm 5.6.0</p>
  
  <p>I want to give to my users the ability to send a mail or mailing to a selection of recipients, based upon some cross selection of fields values. </p>
  
  <p>Views is a good tool for this cross selection and to get a recipients list.</p>
  
  <p>But then, how can I pass this list to the Mailing Form ?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-07T16:03:58.897Z
Comments.Text: I'm assuming the field values for the cross selection are Drupal fields, not CiviCRM fields?
Comments.UserDisplayName: Tony Horrocks
Tags: <civimail><drupal-views>
Title: How to use Views to send a Mailing to a Selection of Recipients?
ThreadText: # How to use Views to send a Mailing to a Selection of Recipients?
  
  (Asked by: username_0 on 2018-11-07)
  
  Drupal 7.60, Civicrm 5.6.0
  
  I want to give to my users the ability to send a mail or mailing to a selection of recipients, based upon some cross selection of fields values.
  
  Views is a good tool for this cross selection and to get a recipients list.
  
  But then, how can I pass this list to the Mailing Form ?
  
  **Tags:** civimail, drupal-views
  
  > **Comments:**
  > **username_1**: I'm assuming the field values for the cross selection are Drupal fields, not CiviCRM fields?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-11-08. Score: 1 | Accepted answer
  
  I'm assuming what you have is a bunch of Drupal users that you are segmenting using Drupal field values.
  
  Step 1 Go here civicrm/admin/synchUser?reset=1 and make sure all your Drupal users are in CiviCRM.
  
  Step 2. Create a custom field for an individual. Make it Yes/No. Call it My Group or whatever. Make it searchable.
  
  Step 3. Make sure that you have the custom field group added to the database config in settings.php /civicrm/admin/setting/uf?reset=1 so you can use it in Drupal Views.
  
  Step 4. Create a view of CiviCRM contacts. Use a Drupal UID relationship so you can filter them into the group you want. Add the custom field you created in Step 2 to the view. Add a VBO filed. Modify the Entity value of the custom field. Bulk edit the custom field and set it to 1.
  
  Step 5. Go to CiviCRM and search for contacts with the custom field set to yes. Add them to a new Mailing Group.
  
  So you could have this as a smart group. You users just have to use VBO to add in the custom field value to update the smart group.
  
  > **Comments:**
  > **username_0**: Thank you Tony : seems clever and smart ! Just one missing step : how would you automatically unflag the custom field afterwards (in order to use the same smart Group for other mailings) ?  
  > **username_1**: Maybe dont do that....What you could do is have a custom field for each mailing group in CiviCRM - so checking/unchecking them in VBO dynamically changes membership of each smart group....  
  > **username_0**: I have to think about it  
  > **username_0**: I have an other concern : when I create a new custom field (Yes/No, searchable), it does not appear in the VBO config Token List, while all other existing custom fields are listed. Any idea to fix that ?  
  > **username_1**: Check it's in a custom field group that you added into your settings.php file - CiviCRM CMS integration etc etc. Also, does it have to be added in as a field in the view before you can access it?  
  > **username_0**: All the other custom fields of the same group appear (this confirm that the pertainig table is included in the settings) + they are displayed in the list even thouh not included as View fields (just 2 or 3 of those are included in the View).  
  > **username_0**: Moreover, this custom field group contains 16 custom fields, including this last created : all the 15 others are displayed in the VBO list. I check your answer + I have just openned a new post on this subject : https://civicrm.stackexchange.com/questions/27297/views-bulk-operation-vbo-config-list-does-not-display-a-custom-field  
  
  ---
  
  ### Answer by username_2 on 2018-11-07. Score: 0
  
  You can create mailing jobs and execute them programmatically.
  
  Process:
  
  1. Create a mailing
  2. Create mailing job through code:
  3. `$new_job = new CRM_Mailing_BAO_MailingJob();
     $params = array(
     'mailing_id' => MAILING_ID,
     'status' => 'Scheduled',
     'scheduled_date' => date('YmdHis'),
     'is_test' => 0,
     );
     $new_job->create($params);// Save job in database`
  4. Execute mailing job through code:
  5. `CRM_Mailing_BAO_MailingJob::runJobs();
     CRM_Mailing_BAO_MailingJob::runJobs_post();`
  
  Hope that will lead you towards your goal.
  
  > **Comments:**
  > **username_0**: Thank you Hassan for your input ; I am not a programmer, but this may be useful. But my concern is about transfering my list of selected contacts from Drupal Views to a mailing list.  
  > **username_2**: Sorry to talk in programming sense again, but i could think of doing this using PHP sessions. Through session in views as Views PHP field you can set session with variable containing info of selected contacts and use that session when creating mailing list. You would need this module for using php in views. https://www.drupal.org/project/views_php  
  
  ---
  
  