In Views Bulk Operations there is an option to send emails to a bunch of users if you select them. What email does it send and where do you edit this email?

Comments

infojunkie’s picture

Priority: Critical » Normal
Status: Active » Fixed

When you select the "Send email" operation in VBO, you are prompted with the email parameters, including recipient, subject and body.

You can also pre-populate these parameters in Site configuration > Actions > Manage actions. There, select "Send email" in the "Make a new advanced action available" drop-down and fill the parameters, also giving a new name to that email-sending action. Then, in the VBO settings, select this new action. When you select the new action on the VBO view page, the parameters that you pre-entered will be used automatically.

vip_sa’s picture

Status: Fixed » Active

I think I explained myself wrong.

I have a bunch of users on my site. I want to use VBO to send all of them an email at once. Now I have created a view with VBO that lists all the users on my site. If I select send email it doesn't give me the oppotunity to edit an email it just sends it and so I don't know what email is sent to the users. If I use the other option of sending an email it asks me to who I would like to send the email but then what is the point of using VBO because if I selecvted a bunch of people why is it still asking me for a recipient? How do I send an email to all the users of my site? That option is not available as aprt of Drupal and so that is why I thought of using VBO

vip_sa’s picture

How do I email all the users of my website at once? That is all the people that have registered and have profiles on my site?

likewhoa’s picture

I have latest -dev and when selecting a bunch of users and selecting either "send email or send tokenized email" the email is sent to the users that's logged in not users selected in VBO. This is on drupal 6.14 and -dev modules.

infojunkie’s picture

Status: Active » Fixed

This feature is available. Here's how to do it:

* Create a VBO that lists users
* Add the "Send tokenized e-mail" operation
* Select a bunch of users then press "Execute"
* In the "Set parameters for 'Send tokenized e-mail'" page, set the recipient as [mail]
* Submit

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joachim’s picture

Status: Closed (fixed) » Active

We still have a bug here:

- What does "Send e-mail (system_send_email_action)" actually do? If it is not useful for a VBO listing users, then it should be removed in this context. If it is useful for something else, it needs a better description to say what it does, and to prevent users like myself and other commenters here misunderstanding it. At the moment, it LOOKS like what it will do is email the users I select in a user VBO, and it doesn't.
- A note in the docs on how to send emails to users in a user VBO would be useful. The string 'Send tokenized e-mail' appears nowhere in the VBO module. A google suggests this is in Rules, but it's in fact the Token Actions module.

joachim’s picture

Category: support » bug

And actually, something better than 'send tokenized email' action is needed.

* Create a VBO that lists users
* Add the "Send tokenized e-mail" operation
* Select a bunch of users then press "Execute"
* In the "Set parameters for 'Send tokenized e-mail'" page, set the recipient as [mail]

This workflow is really non-intuitive. I can't feasibly hand this to clients. Even if they DO open the token list and make it through there, this token description is useless:

[mail] User's email address

So part bug report (bad UI text) and part feature request :)

infojunkie’s picture

Version: 6.x-1.8 » 6.x-1.x-dev
Status: Active » Closed (fixed)

As per #644888: Usability improvements for "Send e-mail" action, you can now use the standard "Send e-mail" action which will not ask you for the recipient anymore. It's in the latest dev.

joachim’s picture

Reading that patch, it seems that this improvement works for node views and adds the node authors to email actions run on views of nodes?
This is not the subject of this issue -- sending emails to users in a view of users.

joachim’s picture

Title: What email does it send? » Change labelling of 'send email action', as it doesn't.
Status: Closed (fixed) » Active

Actually, there is a bug here still: we have an action that appears to do something and doesn't do it. So UI needs fixing.

BenK’s picture

Subscribing...

joachim’s picture

The best way to actually fix this would be to send the system_send_email_action the data. It actually expects a $context['recipient']; so that data could be placed into the $context quite easily by VBO.

The harder part is where to do this in views_bulk_operations_form in an extensible way. I would suggest two things:
- in VIEWS_BULK_OPS_STEP_CONFIG, give modules a chance to alter the form; and do this on behalf of system actions in this particular case
- in views_bulk_operations_form_submit, give modules a change to massage the $context data that is about to be sent to actions. And again, on behalf of system module, get the Views data and extract the user emails from it.

joachim’s picture

In the meantime, here is a filthy hack workaround:

// where 1 is the index of the VBO on the page where it appears; only a factor if you put more than one VBO on a page
function MYMODULE_form_views_bulk_operations_form__1_alter(&$form, &$form_state) {
  if ($form_state['values']['operation'] == 'token_actions_send_email_action' && $form['step']['#value'] == VIEWS_BULK_OPS_STEP_CONFIG) {
    $form['recipient']['#default_value'] = '[mail]';
    $form['recipient']['#disabled'] = TRUE;
    $form['recipient']['#description'] = t('Mail will be sent to all selected users.');
  }
}
joachim’s picture

For reference for anyone trying to fix this the clean way: it's complex :)

VBO tries to submit the configuration form for the action:

    $operation_arguments = _views_bulk_operations_action_submit($operation, $form, $form_state);

So if we hide the recipient field, Drupal core's send email action will choke because it has no recipient field value at all. I suppose the hacky workaround for that is to give it a dummy value and remove it again after, but that's not pretty.
You then need to get the selected users' email addresses into $operation['callback arguments']; again easier said than done --

// Execute the VBO.
$operation = $plugin->get_operation_info($form_state['storage'][VIEWS_BULK_OPS_STEP_VIEW]['operation']);

In some steps, that $form_state value is a scalar not an array!

That's as far as I got before giving up and going for the quick fix.

infojunkie’s picture

Thanks for your initiative to solve this issue.

In the latest dev, you can find the function views_bulk_operations_form_alter around line 389 that does something similar (which currently only works correctly for node views). You can use this as a starting point for your fix.

joachim’s picture

Status: Active » Needs review

Turns out disabling the form element breaks email sending for a reason I can't fathom.

This works:

function MYMODULE_form_views_bulk_operations_form__1_alter(&$form, &$form_state) {
  /*
  constant values are:
  define('VIEWS_BULK_OPS_STEP_VIEW', 1);
  define('VIEWS_BULK_OPS_STEP_CONFIG', 2);
  define('VIEWS_BULK_OPS_STEP_CONFIRM', 3);
  define('VIEWS_BULK_OPS_STEP_SINGLE', 4);
  */
  if ($form_state['values']['operation'] == 'token_actions_send_email_action' && $form['step']['#value'] == VIEWS_BULK_OPS_STEP_CONFIG) {
    $form['recipient']['#default_value'] = '[mail]';
    // $form['recipient']['#disabled'] = TRUE; // this breaks the mail sending WTF?
    $form['recipient']['#access'] = FALSE; // Don't show the field at all.
  }
}

I would suggest this as a patch on the module; though it would have to be done in regular hook_form_alter to cover the case that several VBO forms are on one page (in which case the 1 in views_bulk_operations_form__1 is not valid).
But then the check of $form['step']['#value'] might catch use of this form outside of VBO....

infojunkie’s picture

Category: bug » feature
Status: Needs review » Postponed

I am postponing this until I figure out a more generic way to override actions during VBO execution.

goose2000’s picture

joachim,

I desperately need to implement this patch/hack. Where does this function go ?

function MYMODULE_form_views_bulk_operations_form__1_alter

Did you just write a small module to override this? Or did you add this to the VBO.module ?

I tried the tokenized email idea above, but the token didn't translate, got error:

warning: mail() [function.mail]: SMTP server response: 550 5.1.1 <[mail]>... User unknown in D:\Inetpub\wwroot\drupal_ssw_events\includes\mail.inc on line 193.

Thanks

Patroclas’s picture

Version: 6.x-1.x-dev » 6.x-1.10

This is totally confusing.

How do I send a mass email to selected users in a view of type 'user' using 6.x-1.10 ? Is it possible or not? From my own testing it looks to be impossible, which is not good.

infojunkie’s picture

Status: Postponed » Closed (won't fix)

The module Views Send should fix mass email sending woes. I'm not attempting to fix the core email action anymore.

Patroclas’s picture

Thank you! - I did not know about that module.

Thanks for your work on VBO - it's appreciated.

joachim’s picture

> I'm not attempting to fix the core email action anymore.

Could the label for the core email action be changed at least, so developers don't tear their hair out trying to configure something that won't do what they want?

Tulika’s picture

Issue summary: View changes