You are here

class AmazonSes in Amazon SES 2.0.x

Amazon SES mail system plugin.

Plugin annotation


@Mail(
  id = "amazon_ses_mail",
  label = @Translation("Amazon SES mailer"),
  description = @Translation("Sends an email using Amazon SES.")
)

Hierarchy

Expanded class hierarchy of AmazonSes

File

src/Plugin/Mail/AmazonSes.php, line 22

Namespace

Drupal\amazon_ses\Plugin\Mail
View source
class AmazonSes extends PhpMail implements MailInterface, ContainerFactoryPluginInterface {
  use AmazonSesHandlerTrait;

  /**
   * The config object.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $config;

  /**
   * The queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $queue;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = new static($container, $configuration, $plugin_id, $plugin_definition);
    $instance
      ->setHandler($container
      ->get('amazon_ses.handler'))
      ->setConfig($container
      ->get('config.factory'))
      ->setQueue($container
      ->get('queue'));
    return $instance;
  }

  /**
   * Set the config object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory object.
   *
   * @return $this
   */
  protected function setConfig(ConfigFactoryInterface $config_factory) {
    $this->config = $config_factory
      ->get('amazon_ses.settings');
    return $this;
  }

  /**
   * Set the queue object.
   *
   * @param \Drupal\Core\Queue\QueueFactory $queue_factory
   *   The queue factory service.
   *
   * @return $this
   */
  protected function setQueue(QueueFactory $queue_factory) {
    $this->queue = $queue_factory
      ->get('amazon_ses_mail_queue');
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function mail(array $message) {
    if ($this->config
      ->get('queue')) {
      $result = $this->queue
        ->createItem($message);
      return (bool) $result;
    }
    else {
      $message_id = $this->handler
        ->send($message);
      return (bool) $message_id;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AmazonSes::$config protected property The config object.
AmazonSes::$queue protected property The queue object.
AmazonSes::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
AmazonSes::mail public function Sends an email message. Overrides PhpMail::mail
AmazonSes::setConfig protected function Set the config object.
AmazonSes::setQueue protected function Set the queue object.
AmazonSesHandlerTrait::$handler protected property The Amazon SES handler service.
AmazonSesHandlerTrait::setHandler protected function Set the handler object.
PhpMail::$configFactory protected property The configuration factory.
PhpMail::format public function Concatenates and wraps the email body for plain-text mails. Overrides MailInterface::format 1
PhpMail::MAILBOX_LIST_HEADERS private constant A list of headers that can contain multiple email addresses.
PhpMail::_isShellSafe protected static function Disallows potentially unsafe shell characters.
PhpMail::__construct public function PhpMail constructor.