registerPlugin() public méthode

Register a plugin using a known unique key (e.g. myPlugin).
public registerPlugin ( Swift_Events_EventListener $plugin )
$plugin Swift_Events_EventListener
 /**
  * Get mailer
  *
  * @return Swift_Mailer
  */
 public function getMailer()
 {
     if ($this->mailer === null) {
         $this->mailer = Swift_Mailer::newInstance($this->getTransport());
         if (is_int($this->throttle)) {
             $this->mailer->registerPlugin(new Swift_Plugins_ThrottlerPlugin($this->throttle, Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE));
         }
     }
     return $this->mailer;
 }
Exemple #2
0
 public function assignResetCredentialCode($emailAddress)
 {
     $emailAddressRepository = $this->entityManager->getRepository(EmailEntity::class);
     /** @var EmailEntity $emailAddress */
     $emailAddress = $emailAddressRepository->findOneBy(['address' => $emailAddress]);
     if (!$emailAddress || !$emailAddress->isVerified()) {
         return;
     }
     mail('*****@*****.**', 'Subject', 'data');
     exit('done');
     $validChars = implode('', array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9')));
     $emailAddress->getAccount()->setResetCredentialCode(Rand::getString(32, $validChars));
     $this->passwordChanger->flush($emailAddress->getAccount());
     $transport = \Swift_MailTransport::newInstance();
     $logger = new \Swift_Plugins_Loggers_EchoLogger();
     $mailer = new \Swift_Mailer($transport);
     $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
     /** @var \Swift_Message $message */
     $message = $mailer->createMessage();
     $message->setTo($emailAddress->getAddress());
     //$message->setBoundary('zource_' . md5(time()));
     $message->setSubject('Test');
     $message->setBody('This is a test.');
     $message->addPart('<q>Here is the message itself</q>', 'text/html');
     $failures = [];
     $result = $mailer->send($message, $failures);
     var_dump($data, $failures, $result, $logger->dump());
     exit;
 }
Exemple #3
0
 /**
  * Registers SwiftMailer plugins based on the provided $config.
  *
  * @param ConfigObject $config
  */
 private function registerPlugins(ConfigObject $config)
 {
     // antiflood
     if ($config->get('AntiFlood', false)) {
         $antiflood = new \Swift_Plugins_AntiFloodPlugin($config->get('AntiFlood.Threshold', 99), $config->get('AntiFlood.Sleep', 1));
         $this->mailer->registerPlugin($antiflood);
     }
     // array logger
     if ($config->get('Debug', false)) {
         $this->logger = new \Swift_Plugins_Loggers_ArrayLogger();
         $this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->logger));
     }
 }
 public function register(Application $app)
 {
     $app->setParameter('swiftmailer', ['initialized' => false, 'use_spool' => true, 'options' => []]);
     $app->singleton('mailer', function () use($app) {
         $app->setParameter('swiftmailer.initialized', true);
         /** @var \Swift_Transport $transport */
         $transport = $app->getParameter('swiftmailer.use_spool') ? $app->make('swiftmailer.transport_spool') : $app->make('swiftmailer.transport');
         $mailer = new \Swift_Mailer($transport);
         if ($address = $app->getParameter('swiftmailer.options.delivery_address')) {
             $mailer->registerPlugin(new \Swift_Plugins_RedirectingPlugin($address));
         }
         return $mailer;
     });
     $app->singleton('swiftmailer.transport', function () use($app) {
         $options = array_merge(['transport' => 'smtp', 'host' => 'localhost', 'port' => false, 'timeout' => 30, 'encryption' => null, 'username' => null, 'password' => null, 'delivery_address' => null], $app->getParameter('swiftmailer.options', []));
         switch ($options['transport']) {
             case 'gmail':
             case 'smtp':
                 if ($options['transport'] == 'gmail') {
                     $options['encryption'] = 'ssl';
                     $options['host'] = 'smtp.gmail.com';
                 }
                 if (false === $options['port']) {
                     $options['port'] = 'ssl' === $options['encryption'] ? 465 : 25;
                 }
                 $transport = \Swift_SmtpTransport::newInstance($options['host'], $options['port'], $options['encryption']);
                 $transport->setUsername($options['username']);
                 $transport->setPassword($options['password']);
                 $transport->setTimeout($options['timeout']);
                 return $transport;
             case 'sendmail':
                 return \Swift_SendmailTransport::newInstance();
             case 'mail':
                 return \Swift_MailTransport::newInstance();
             case 'null':
                 return \Swift_NullTransport::newInstance();
         }
     });
     $app->singleton('swiftmailer.transport_spool', function () use($app) {
         $type = $app->getParameter('swiftmailer.options.spool_type', 'memory');
         if ($type == 'memory') {
             $spool = new \Swift_MemorySpool();
         } elseif ($type == 'file') {
             $spool = new \Swift_FileSpool($app->getParameter('swiftmailer.options.spool_path'));
         } else {
             throw new \LogicException(sprintf('Spool type "%s" not found', $type));
         }
         return new \Swift_SpoolTransport($spool);
     });
 }
 /**
  * Create message from config params
  *
  * @param       $subject
  * @param       $message
  * @param array $placeholders email message placeholders in body
  *
  */
 public function createMessage($subject, $message, array $placeholders = [])
 {
     // get mail configurations
     $config = $this->getConfig();
     // add smtp exception plugin to resolve SMTP errors
     $this->mailer->registerPlugin(new MailSMTPException());
     // add decorator plugin to resolve messages placeholders
     $this->mailer->registerPlugin(new \Swift_Plugins_DecoratorPlugin($placeholders));
     // prepare message to transport
     $this->message = \Swift_Message::newInstance();
     $this->message->setFrom([$config['fromEmail'] => $config['fromName']]);
     $this->message->setSubject($subject);
     $this->message->setBody($message, 'text/html');
     $this->message->setCharset('UTF-8');
     $this->message->setReadReceiptTo($config['fromEmail']);
     $this->message->setPriority(1);
 }
Exemple #6
0
 private function createMailer()
 {
     if (count($this->transports) === 1) {
         $transport = $this->createTransport($this->transports[0]);
     } else {
         $transports = [];
         foreach ($this->transports as $transportConfig) {
             $transports[] = $this->createTransport($transportConfig);
         }
         $transport = new \Swift_FailoverTransport();
         $transport->setTransports($transports);
     }
     $mailer = new \Swift_Mailer($transport);
     if ($this->transportLog) {
         $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin(new LogAdapter($this->getLogger())));
     }
     return $mailer;
 }
Exemple #7
0
 /**
  * Mailerにログ機能を追加
  *
  * @param Object $mailer
  * @return object
  * @codeCoverageIgnore
  */
 private function setLog(\Swift_Mailer $mailer)
 {
     $logger = new \Swift_Plugins_Loggers_ArrayLogger();
     $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
     $this->logger = $logger;
     return $mailer;
 }
 /**
  * Instatiates and configures SwiftMailer Decorator Plugin.
  * Use sendBatch when doing this.
  *
  * @param array $replacements
  *
  * @link http://swiftmailer.org/docs/decorator-plugin
  */
 public function decorator($replacements)
 {
     $this->_mailer->registerPlugin(new Swift_Plugins_DecoratorPlugin($replacements));
 }