Cloned the views_send module for my particular purposes, and it works just fine for user 1.
But for any other user, mails are not sent, $status in the following code snippet is NULL:

function group_send_deliver($message) {
  if (is_array($message)) {
    $message = (object) $message;
  }

  $key = 'direct';
  $headers = unserialize($message->headers);

  $mail = array(
    'id' => 'group_send_' . $key,
    'module' => 'group_send',
    'key' => $key,
    'to' => $message->to_mail,
    'from' => $message->from_mail,
    'subject' => $message->subject,
    'body' => $message->body,
    'headers' => $headers,
  );

  // Because of Swifth Mailer issue 2841663
  if (module_exists('swiftmailer')) {
    $mail['params'] = $message->params;
  }

  // Mime encode the subject before passing to the mail function 
  // to work around a bug in Drupal's mime_header_encode.
  $mail['subject'] = _group_send_mime_header_encode($message->subject);
  
  $system = drupal_mail_system('group_send', $key);

  return $system->mail($mail);
}

/**
 * Preparing and sending a message (coming from a batch job).
 */
function group_send_batch_deliver($message, $plain_format, $attachments, &$context) {
  _group_send_prepare_mail($message, $plain_format, $attachments);
  if (!$message['send']) {
    $context['results'][] = t('Skipping sending message to %mail.',
      array('%mail' => $message['to_mail']));
    return;
  }
  else {
    unset($message['send']);
  }
  
  $status = group_send_deliver($message);

  if ($status) {
 //   if (variable_get('group_send_debug', FALSE)) {
      watchdog('group_send', 'Message sent to %mail.', array('%mail' => $message['to_mail']));
 //   }
    if (module_exists('rules')) {
      rules_invoke_event('group_send_email_sent', $message);
    }
  }
  else {
    $context['results'][] = t('Failed sending message to %mail - spooling it',
      array('%mail' => $message['to_mail']));
    // Queue the message to the spool table.
    db_insert('group_send_spool')->fields($message)->execute();
    if (module_exists('rules')) {
      rules_invoke_event('group_send_email_added_to_spool', $message);
    }
  }
}

I tried to identify the cause, but couldn't find anything. Help, please.

Comments

thomas.wardin created an issue. See original summary.

hansfn’s picture

Status: Active » Postponed (maintainer needs more info)

There is only one possible explanation AFAICT for this behavior - missing permission to send e-mails (in general). This isn't something that Views Send is controlling (at this point in the code). The missing permission can be a core permission or from a mail related module you have installed.

On a side note: Why do you need to "clone"/duplicate the Views Send module? Could the module be made more configurable/flexible so you don't have to "clone" it?

thomas.wardin’s picture

Thank you for your quick reply.

I could not find any permission which would not be set. Do you think of anything particular?

Despite reproducing the configuration of a working site with views_send, my clone still works only for user 1.

Could however narrow down the case:
- phpmailer tested successfully as user 1 and as another user with admin role
- returned status is 1 when user 1, empty when the other user

So it appears like the mail-call doesn't work as expected. Do you have any hint how to further test?

thomas.wardin’s picture

Clarified with the provider that mails with unknown senders are rejected by sendmail (though without a visible error message).
I will change the Sender address to uniformely be the user 1 address and add the originator's address as Reply-to.

BTW: I need the module clone because my use case is to mail to an entire group (identified by taxonomy term). So I have the user check the group(s), resolve the addresses within these groups and then process the array_unique. Appears to me to be too different from the original case.

hansfn’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Thx for reporting back. I'm closing the issue as "works as designed".

Yeah, maybe you need to clone it. Anyway, I don't have time to verify if can be done or not ;-)