function __construct(LoggerInterface $logger, \Swift_Transport $transport) { $this->logger = $logger; // We register the plugin here and not using the swiftmailer.plugin tag // to avoid the ServiceCircularReferenceException we get when Monolog is // configured to mail the messages through SwiftMailer. $transport->registerPlugin(new \Swift_Plugins_LoggerPlugin($this)); }
/** * @internal * @return null|\Swift_Mailer */ protected function getMailer() { if (!$this->enabled()) { return null; } if (!$this->mailer) { /** @var Config $config */ $config = self::getGrav()['config']; $mailer = $config->get('plugins.email.mailer.engine'); // Create the Transport and initialize it. switch ($mailer) { case 'smtp': $transport = \Swift_SmtpTransport::newInstance(); $options = $config->get('plugins.email.mailer.smtp'); if (!empty($options['server'])) { $transport->setHost($options['server']); } if (!empty($options['port'])) { $transport->setPort($options['port']); } if (!empty($options['encryption']) && $options['encryption'] != 'none') { $transport->setEncryption($options['encryption']); } if (!empty($options['user'])) { $transport->setUsername($options['user']); } if (!empty($options['password'])) { $transport->setPassword($options['password']); } break; case 'sendmail': $options = $config->get('plugins.email.mailer.sendmail'); $bin = !empty($options['bin']) ? $options['bin'] : '/usr/sbin/sendmail'; $transport = \Swift_SendmailTransport::newInstance($bin); break; case 'mail': default: $transport = \Swift_MailTransport::newInstance(); } // Create the Mailer using your created Transport $this->mailer = \Swift_Mailer::newInstance($transport); // Register the logger if we're debugging. if ($this->debug()) { $this->logger = new \Swift_Plugins_Loggers_ArrayLogger(); $this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->logger)); } } return $this->mailer; }