3 namespace Drupal\Core\Mail\Plugin\Mail;
5 use Drupal\Core\Mail\MailInterface;
8 * Defines a mail backend that captures sent messages in the state system.
10 * This class is for running tests or for development.
13 * id = "test_mail_collector",
14 * label = @Translation("Mail collector"),
15 * description = @Translation("Does not send the message, but stores it in Drupal within the state system. Used for testing.")
18 class TestMailCollector extends PhpMail implements MailInterface {
23 public function mail(array $message) {
24 $captured_emails = \Drupal::state()->get('system.test_mail_collector') ?: [];
25 $captured_emails[] = $message;
26 \Drupal::state()->set('system.test_mail_collector', $captured_emails);