You are here

public function MandrillTestAPI::send in Mandrill 8

The function that calls the API send message.

This is the default function used by mandrill_mailsend().

Parameters

array $message: Associative array containing message data.

Return value

array Results of sending the message.

Throws

\Exception

Overrides MandrillAPI::send

File

src/MandrillTestAPI.php, line 191

Class

MandrillTestAPI
Overrides functions in the Mandrill API service for testing.

Namespace

Drupal\mandrill

Code

public function send(array $message) {
  if (!isset($message['to']) || empty($message['to'])) {
    return $this
      ->getErrorResponse(12, 'ValidationError', 'No recipients defined.');
  }
  $response = array();
  foreach ($message['to'] as $recipient) {
    $recipient_response = array(
      'email' => $recipient['email'],
      'status' => '',
      'reject_reason' => '',
      '_id' => uniqid(),
    );
    if (\Drupal::service('email.validator')
      ->isValid($recipient['email'])) {
      $recipient_response['status'] = 'sent';
    }
    else {
      $recipient_response['status'] = 'invalid';
    }
    $response[] = $recipient_response;
  }
  return $response;
}