Problem/Motivation

The \Drupal\mailgun\MailgunHandler::sendMail method will log a success message when debug is turned on and an error message when an exception occurs. However when the message comes from a queue the \Drupal\mailgun\Plugin\QueueWorker\SendMailBase::processItem always logs a success message when debug is turned on regardless of whether the mail has been sent or not.

\Drupal\mailgun\MailgunHandler::sendMail

      $response = $this->mailgun->messages()->send($domain, $mailgunMessage);

      // Debug mode: log all messages.
      if ($this->mailgunConfig->get('debug_mode')) {
        $this->logger->notice('Successfully sent message from %from to %to. %id %message.',
          [
            '%from' => $mailgunMessage['from'],
            '%to' => $this->getRecipients($mailgunMessage),
            '%id' => $response->getId(),
            '%message' => $response->getMessage(),
          ]
        );
      }
      return $response;

\Drupal\mailgun\Plugin\QueueWorker\SendMailBase::processItem

  public function processItem($data) {
    $result = $this->mailgunHandler->sendMail($data->message);

    if ($this->mailgunConfig->get('debug_mode')) {
      $this->logger->notice('Successfully sent message on CRON from %from to %to.',
        [
          '%from' => $data->message['from'],
          '%to' => $data->message['to'],
        ]
      );
    }

    if (!$result) {
      throw new \Exception('Mailgun: email did not pass through API.');
    }
  }

Steps to reproduce

Turn on debug and queuing, and send a test email to a non existent/invalid email address that the API will reject e.g. 'test@example'. Process the queue and you will get an error message saying the API call failed, and a success message saying "Successfully sent message on CRON from Site email <...> to test@example."

Proposed resolution

As there is already a debug success message in \Drupal\mailgun\MailgunHandler::sendMail the simplest solution is to remove the one in \Drupal\mailgun\Plugin\QueueWorker\SendMailBase::processItem

Support from Tag1 fosters the development of DrupalTag1 logo

Comments

Altcom_Neil created an issue. See original summary.

Altcom_Neil’s picture