You are here

public function MailgunMail::queueMessage in Mailgun 8

Queue a message for sending.

Parameters

array $message: Mailgun message array that was build and ready for sending.

Return value

bool TRUE if the message was queued, otherwise FALSE.

2 calls to MailgunMail::queueMessage()
MailgunMail::mail in src/Plugin/Mail/MailgunMail.php
Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().
MailgunQueueMail::mail in src/Plugin/Mail/MailgunQueueMail.php
Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().

File

src/Plugin/Mail/MailgunMail.php, line 138

Class

MailgunMail
Default Mailgun mail system plugin.

Namespace

Drupal\mailgun\Plugin\Mail

Code

public function queueMessage(array $message) {

  /** @var \Drupal\Core\Queue\QueueInterface $queue */
  $queue = $this->queueFactory
    ->get('mailgun_send_mail');
  $item = new \stdClass();
  $item->message = $message;
  $result = $queue
    ->createItem($item);
  if ($result !== FALSE) {

    // Debug mode: log all messages.
    if ($this->mailgunConfig
      ->get('debug_mode')) {
      $this->logger
        ->notice('Successfully queued message from %from to %to.', [
        '%from' => $message['from'],
        '%to' => $message['to'],
      ]);
    }
  }
  else {
    $this->logger
      ->error('Unable to queue message from %from to %to.', [
      '%from' => $message['from'],
      '%to' => $message['to'],
    ]);
  }
  return !empty($result);
}