/** * * @param array $options * @throws Exception */ protected function setOptions(array $options) { if (!isset($options['transport']['name'])) { throw new Exception('No mail transport.'); } $transportClass = $options['transport']['name']; if ($transportClass == Sendmail::class && isset($options['transport']['options'])) { $this->transport = new $transportClass($options['transport']['options']); } else { $this->transport = new $transportClass(); } if (!$this->transport instanceof TransportInterface) { throw new Exception('Transport must implement Zend\\Mail\\Transport\\TransportInterface'); } if (method_exists($this->transport, 'getOptions')) { $transportOptions = $this->transport->getOptions(); $transportOptions->setFromArray($options['transport']['options']); $this->transport->setOptions($transportOptions); } }
/** * Configures specific transport options * @param TransportInterface $transport * @param MailOptions $mailOptions */ protected function setupSpecificConfig(TransportInterface $transport, MailOptions $mailOptions) { if ($transport instanceof Smtp) { $connConfig = array('username' => $mailOptions->getSmtpUser(), 'password' => $mailOptions->getSmtpPassword()); // Check if SSL should be used if ($mailOptions->getSsl() !== false) { $connConfig['ssl'] = $mailOptions->getSsl(); } // Set SMTP transport options $transport->setOptions(new SmtpOptions(array('host' => $mailOptions->getServer(), 'port' => $mailOptions->getPort(), 'connection_class' => $mailOptions->getConnectionClass(), 'connection_config' => $connConfig))); } elseif ($transport instanceof File) { $transport->setOptions(new FileOptions(array('path' => $mailOptions->getFilePath(), 'callback' => $mailOptions->getFileCallback()))); } }
/** * Get the mail transport object. * * @return \Zend\Mail\Transport\TransportInterface */ public function getTransport() { // Create transport if it does not already exist: if (is_null($this->transport)) { $settings = array('host' => $this->config->Mail->host, 'port' => $this->config->Mail->port); if (isset($this->config->Mail->username) && isset($this->config->Mail->password)) { $settings['connection_class'] = 'login'; $settings['connection_config'] = array('username' => $this->config->Mail->username, 'password' => $this->config->Mail->password); } $this->transport = new Smtp(); $this->transport->setOptions(new SmtpOptions($settings)); } return $this->transport; }
/** * Get message transport * * @return \Zend\Mail\Transport\TransportInterface */ protected static function getMessageTransport() { if (!self::$messageTransport) { // should we use SMTP? if ((int) ApplicationSettingService::getSetting('application_use_smtp')) { self::$messageTransport = new SmtpTransport(); // get connection config $connectionConfig = []; // get smtp ssl if (null != ($smtpSsl = ApplicationSettingService::getSetting('application_smtp_ssl'))) { $connectionConfig['ssl'] = $smtpSsl; } // get smtp user if (null != ($smtpUsername = ApplicationSettingService::getSetting('application_smtp_user'))) { $connectionConfig['username'] = $smtpUsername; } // get smtp password if (null != ($smtpPassword = ApplicationSettingService::getSetting('application_smtp_password'))) { $connectionConfig['password'] = $smtpPassword; } // set global options $globalOptions = []; // get smtp host if (null != ($smtpHost = ApplicationSettingService::getSetting('application_smtp_host'))) { $globalOptions['host'] = $smtpHost; } // get connection class if (null != ($smtpConnection = ApplicationSettingService::getSetting('application_smtp_login'))) { $globalOptions['connection_class'] = $smtpConnection; } // get connection config if ($connectionConfig) { $globalOptions['connection_config'] = $connectionConfig; } // get smtp port if (null != ($smtpPort = ApplicationSettingService::getSetting('application_smtp_port'))) { $globalOptions['port'] = $smtpPort; } $options = new SmtpOptions($globalOptions); self::$messageTransport->setOptions($options); return self::$messageTransport; } self::$messageTransport = new SendmailTransport(); } return self::$messageTransport; }
/** * @param TransportInterface $transport * @return TransportInterface */ protected function setupTransportConfig(TransportInterface $transport) { if ($transport instanceof Smtp) { $transport->setOptions($this->mailOptions->getSmtpOptions()); } elseif ($transport instanceof File) { $transport->setOptions($this->mailOptions->getFileOptions()); } return $transport; }