You are here

function views_send_batch_deliver in Views Send 8

Same name and namespace in other branches
  1. 7 views_send.module \views_send_batch_deliver()

Preparing and sending a message (coming from a batch job).

1 string reference to 'views_send_batch_deliver'
views_send_queue_mail in ./views_send.module
Assembles the email and queues it for sending.

File

./views_send.module, line 879
The Views Send module.

Code

function views_send_batch_deliver($message, $plain_format, $attachments, &$context) {
  _views_send_prepare_mail($message, $plain_format, $attachments);
  $status = views_send_deliver($message);
  if ($status) {
    if (\Drupal::config('views_send.settings')
      ->get('debug')) {
      \Drupal::logger('views_send')
        ->notice(t('Message sent to %mail.', array(
        '%mail' => $message['to_mail'],
      )));
    }
    $event = new MailSentEvent($message);
    $event_dispatcher = \Drupal::service('event_dispatcher');
    $event_dispatcher
      ->dispatch(MailSentEvent::EVENT_NAME, $event);
  }
  else {
    $context['results'][] = t('Failed sending message to %mail - spooling it.', array(
      '%mail' => $message['to_mail'],
    ));

    // Queue the message to the spool table.
    \Drupal::database()
      ->insert('views_send_spool')
      ->fields($message)
      ->execute();
    $event = new MailAddedEvent($message);
    $event_dispatcher = \Drupal::service('event_dispatcher');
    $event_dispatcher
      ->dispatch(MailAddedEvent::EVENT_NAME, $event);
  }
}