public function setUp() { parent::setUp(); // create app $config = $this->appConfig + array('base_url' => 'http://localhost/'); $app = new \FelixOnline\Core\App($config); $dbuser = getenv('DB_USER') ? getenv('DB_USER') : 'root'; $dbpass = getenv('DB_PASS') ? getenv('DB_PASS') : ''; $db = new \ezSQL_mysqli(); $db->quick_connect($dbuser, $dbpass, 'test_media_felix', 'localhost', 3306, 'utf8'); $app['db'] = $db; $app['safesql'] = new \SafeSQL_MySQLi($db->dbh); $app['env'] = \FelixOnline\Core\Environment::mock(); // Initialize Akismet $connector = new \Riv\Service\Akismet\Connector\Test(); $app['akismet'] = new \Riv\Service\Akismet\Akismet($connector); // Initialize email $transport = \Swift_NullTransport::newInstance(); $app['email'] = \Swift_Mailer::newInstance($transport); $session = $this->mock('FelixOnline\\Core\\Session')->getId(1)->start(1)->reset()->new(); $this->reflect($session)->__set('session', array()); $app['env']['session'] = $session; $cookies = $this->mock('FelixOnline\\Core\\Cookies')->set(true)->delete(true)->new(); $this->reflect($cookies)->__set('cookies', array()); $app['env']['cookies'] = $cookies; if ($this->setCurrentUser) { $app['currentuser'] = new \FelixOnline\Core\CurrentUser(); } // Set empty cache so data isn't cached in tests $app['cache'] = new \Stash\Pool(); $app->run(); $this->app = $app; }
public static function get() { $mail_function = forum_get_global_setting('mail_function', null, MAIL_FUNCTION_PHP); if ($mail_function == MAIL_FUNCTION_NONE) { return Swift_NullTransport::newInstance(); } if ($mail_function == MAIL_FUNCTION_SMTP && ($smtp_server = forum_get_global_setting('smtp_server'))) { $smtp_port = forum_get_global_setting('smtp_port', null, '25'); $smtp_ssl = forum_get_global_setting('smtp_ssl', 'Y'); $transport = Swift_SmtpTransportSingleton::getInstance($smtp_server, $smtp_port, $smtp_ssl); if (($smtp_username = forum_get_global_setting('smtp_username', 'strlen', false)) !== false) { /** @noinspection PhpUndefinedMethodInspection */ $transport->setUsername($smtp_username); } if (($smtp_password = forum_get_global_setting('smtp_password', 'strlen', false)) !== false) { /** @noinspection PhpUndefinedMethodInspection */ $transport->setPassword($smtp_password); } return $transport; } if ($mail_function == MAIL_FUNCTION_SENDMAIL && ($sendmail_path = forum_get_global_setting('sendmail_path'))) { return Swift_SendmailTransportSingleton::getInstance($sendmail_path); } return Swift_MailTransportSingleton::getInstance(); }
/** * Base constructor. * In the base constructor the bridge gets the mailer configuration. * * @param ConfigObject $config The base configuration. * * @throws SwiftMailerException */ public function __construct($config) { $this->config = $config; $transportType = strtolower($config->get('Transport.Type', 'mail')); $disableDelivery = $config->get('DisableDelivery', false); if ($disableDelivery) { $transportType = 'null'; } // create Transport instance switch ($transportType) { case 'smtp': $transport = \Swift_SmtpTransport::newInstance($config->get('Transport.Host', 'localhost'), $config->get('Transport.Port', 25), $config->get('Transport.AuthMode', null)); $transport->setUsername($config->get('Transport.Username', '')); $transport->setPassword($config->get('Transport.Password', '')); $transport->setEncryption($config->get('Transport.Encryption', null)); break; case 'mail': $transport = \Swift_MailTransport::newInstance(); break; case 'sendmail': $transport = \Swift_SendmailTransport::newInstance($config->get('Transport.Command', '/usr/sbin/sendmail -bs')); break; case 'null': $transport = \Swift_NullTransport::newInstance(); break; default: throw new SwiftMailerException('Invalid transport.type provided. Supported types are [smtp, mail, sendmail, null].'); break; } // create Mailer instance $this->mailer = \Swift_Mailer::newInstance($transport); // register plugins $this->registerPlugins($config); }
public static function createFromConfig(ConfigInterface $config) { $transport = $config->get('mailer_transport'); $host = $config->get('mailer_host'); $port = $config->get('mailer_port'); // 25 or 465 (smtp) $username = $config->get('mailer_username'); $password = $config->get('mailer_password'); $authMode = $config->get('mailer_auth_mode'); $encryption = $config->get('mailer_encryption'); if ($transport == 'gmail') { $transport = 'smtp'; $host = 'smtp.gmail.com'; $authMode = 'login'; $encryption = 'ssl'; $port = 465; } $port = $port ? $port : 25; if ($transport == 'smtp') { $transport = \Swift_SmtpTransport::newInstance($host, $port)->setUsername($username)->setPassword($password); } elseif ($transport == 'mail') { $transport = \Swift_MailTransport::newInstance(); } elseif ($transport == 'null') { $transport = \Swift_NullTransport::newInstance(); } else { throw new \RuntimeException(sprintf('Unable to construct a transport of type "%s"', $transport)); } return \Swift_Mailer::newInstance($transport); }
/** * @return Services */ protected function registerSwiftMailer() : Services { // Register Mailer $this->getContainer()->share(\Swift_Transport::class, function () { return \Swift_NullTransport::newInstance(); }); $this->getContainer()->share(\Swift_Mailer::class, function () { return \Swift_Mailer::newInstance($this->getContainer()->get(\Swift_Transport::class)); }); return $this; }
/** * Constructor * * @param \Swift_Mailer $baseMailer * @param ContainerInterface $container */ public function __construct(\Swift_Mailer $baseMailer, ContainerInterface $container) { $this->baseMailer = $baseMailer; $this->container = $container; $transport = $this->baseMailer->getTransport(); if ($transport instanceof \Swift_Transport_SpoolTransport) { $transport = $this->findRealTransport(); if (!$transport) { $transport = \Swift_NullTransport::newInstance(); } } parent::__construct($transport); }
/** @test **/ public function itShouldConvertHtmlBodyAsAPart() { $mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); $mailer->registerPlugin(new CssInlinerPlugin($this->options)); $message = Swift_Message::newInstance(); $message->setFrom('*****@*****.**'); $message->setTo('*****@*****.**'); $message->setSubject('Test'); $message->addPart($this->stubs['original-html'], 'text/html'); $mailer->send($message); $children = $message->getChildren(); $this->assertEquals($this->stubs['converted-html'], $children[0]->getBody()); }
/** * Creates a SwiftMailer instance. * * @param string DSN connection string * @return object Swift object */ public static function mailer() { if (Email::$_mailer) { return Email::$_mailer; } // Load default configuration $config = Kohana::$config->load('html-email')->as_array(); switch ($config['driver']) { case 'smtp': $transport = Swift_SmtpTransport::newInstance(Arr::path($config, 'options.hostname', 'localhost'), Arr::path($config, 'options.port', 25), Arr::path($config, 'options.encryption')); $transport->setTimeout(Arr::path($config, 'options.timeout', 5)); $user = Arr::path($config, 'options.username'); $pass = Arr::path($config, 'options.password'); if ($user and $pass) { $transport->setUsername($user); $transport->setPassword($pass); } break; case 'sendmail': $transport = Swift_SendmailTransport::newInstance(Arr::get($config, 'options', '/usr/sbin/sendmail -bs')); break; case 'postmark': $transport = Openbuildings\Postmark\Swift_PostmarkTransport::newInstance(Arr::get($config, 'options')); break; case 'null': $transport = Swift_NullTransport::newInstance(); break; default: // Use the native connection $transport = Swift_MailTransport::newInstance(); break; } // Create the SwiftMailer instance self::$_mailer = Swift_Mailer::newInstance($transport); if (Arr::get($config, 'inline_css')) { self::$_mailer->registerPLugin(new Openbuildings\Swiftmailer\CssInlinerPlugin()); } if ($filter = Arr::get($config, 'filter')) { self::$_mailer->registerPlugin(new Openbuildings\Swiftmailer\FilterPlugin(Arr::get($filter, 'whitelist', array()), Arr::get($filter, 'blacklist', array()))); } if ($google_campaign = Arr::path($config, 'google_campaign.campaigns')) { self::$_mailer->registerPlugin(new Openbuildings\Swiftmailer\GoogleCampaignPlugin(array(), array('share' => $google_campaign['share'], 'abandoned_cart' => $google_campaign['abandoned_cart']))); } if ($logger = Arr::get($config, "logger")) { if ($logger === TRUE) { self::$_mailer->registerPlugin(new Swift_Plugins_Fullloggerplugin(new Email_Logger())); } else { self::$_mailer->registerPlugin(new $logger(new Email_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); }); }
/** * Constructor * * @param \Swift_Mailer $baseMailer * @param ContainerInterface $container */ public function __construct(\Swift_Mailer $baseMailer, ContainerInterface $container, ImapEmailGoogleOauth2Manager $imapEmailGoogleOauth2Manager) { $this->baseMailer = $baseMailer; $this->container = $container; $this->imapEmailGoogleOauth2Manager = $imapEmailGoogleOauth2Manager; $transport = $this->baseMailer->getTransport(); if ($transport instanceof \Swift_Transport_SpoolTransport) { $transport = $this->findRealTransport(); if (!$transport) { $transport = \Swift_NullTransport::newInstance(); } } if ($transport instanceof \Swift_Transport_EsmtpTransport) { $this->addXOAuth2Authenticator($transport); } parent::__construct($transport); }
/** * Creates a SwiftMailer instance. * * @param string DSN connection string * @return object Swift object */ public static function get_transport($config = NULL) { if (!class_exists('Swift_Mailer', FALSE)) { require Kohana::find_file('vendor', 'swiftmailer/lib/swift_required'); } // Load default configuration $config === NULL and $config = Kohana::$config->load('email'); if ('smtp' === $config['driver']) { /** * SMTP transport */ $port = empty($config['options']['port']) ? 25 : (int) $config['options']['port']; $transport = Swift_SmtpTransport::newInstance($config['options']['hostname'], $port); if (!empty($config['options']['encryption'])) { $transport->setEncryption($config['options']['encryption']); } empty($config['options']['username']) or $transport->setUsername($config['options']['username']); empty($config['options']['password']) or $transport->setPassword($config['options']['password']); $transport->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']); } elseif ('sendmail' === $config['driver']) { /** * Sendmail transport */ $transport = Swift_SendmailTransport::newInstance(empty($config['options']) ? "/usr/sbin/sendmail -bs" : $config['options']); } elseif ('null' === $config['driver']) { /** * Null transport */ $transport = Swift_NullTransport::newInstance(); } else { /** * Native transport (mail). */ $transport = Swift_MailTransport::newInstance($config['options']); } if (isset($config['logging']) and $config['logging']) { /** * Logs all outgoing email to the database. */ $model = ORM::factory('email'); $database_reporter = new Swift_Plugins_Pixel_Email_Logger_Database($model); $reporter = new Swift_Plugins_ReporterPlugin($database_reporter); $transport->registerPlugin($reporter); } return Swift_Mailer::newInstance($transport); }
/** * Define mail transport * * @param string $default * @return Swift_MailTransport|Swift_SendmailTransport */ private static function transport($default = null) { require path('vendor') . 'Swift/lib/swift_required.php'; $options = Config::get('application.mail'); if (is_null($default)) { $default = $options['transport']; } switch ($default) { case 'sendmail': $transport = Swift_SendmailTransport::newInstance($options['sendmail']['path'] . ' -bs'); break; case 'smtp': $transport = Swift_SmtpTransport::newInstance($options['smtp']['server'], $options['smtp']['port'], $options['smtp']['encryption'])->setUsername($options['smtp']['username'])->setPassword($options['smtp']['password']); break; case 'mail': $transport = Swift_MailTransport::newInstance(); break; default: $transport = Swift_NullTransport::newInstance(); break; } return $transport; }
/** * @return \Swift_Mailer */ private function getSwiftMailerMock() { return $this->getMock('Swift_Mailer', [], [\Swift_NullTransport::newInstance()]); }
<?php /** * 260-transport-null.php */ require_once '../vendor/autoload.php'; require_once './config.php'; // POINT of this sample $transport = Swift_NullTransport::newInstance(); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance(); $message->setFrom(MAIL_FROM)->setTo(MAIL_TO)->setSubject('NullTransport sample')->setBody('This is a mail, but this is not send.'); $result = $mailer->send($message);
public function setUp() { $this->mailer = Swift_Mailer::newInstance(\Swift_NullTransport::newInstance()); $this->mailer->registerPlugin(new ImageEmbedPlugin()); }
/** * Create a Swift_Mailer_Transport. * * @param string $type * @param array $options * @throws \phpbu\App\Exception * @return \Swift_Transport */ protected function createTransport($type, array $options) { switch ($type) { // null transport, don't send any mails case 'null': /* @var $transport \Swift_NullTransport */ $transport = \Swift_NullTransport::newInstance(); break; case 'mail': /* @var $transport \Swift_MailTransport */ $transport = \Swift_MailTransport::newInstance(); break; case 'smtp': $transport = $this->getSmtpTransport($options); break; case 'sendmail': $transport = $this->getSendmailTransport($options); break; // UPS! no transport given // UPS! no transport given default: throw new Exception(sprintf('mail transport not supported: \'%s\'', $type)); } return $transport; }
<?php include __DIR__ . '/vendor/autoload.php'; include __DIR__ . '/../../bootstrap.php'; $debugbarRenderer->setBaseUrl('../../../src/DebugBar/Resources'); use DebugBar\Bridge\SwiftMailer\SwiftLogCollector; use DebugBar\Bridge\SwiftMailer\SwiftMailCollector; $mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance()); $debugbar['messages']->aggregate(new SwiftLogCollector($mailer)); $debugbar->addCollector(new SwiftMailCollector($mailer)); $message = Swift_Message::newInstance('Wonderful Subject')->setFrom(array('*****@*****.**' => 'John Doe'))->setTo(array('*****@*****.**', '*****@*****.**' => 'A name'))->setBody('Here is the message itself'); $mailer->send($message); render_demo_page();
/** * @return \Swift_Transport */ protected function getSwiftmailer_TransportService() { if ($this->getParameter('app.devmode')) { return $this->services['swiftmailer.transport'] = \Swift_NullTransport::newInstance(); } $transport = \Swift_SmtpTransport::newInstance($this->getParameter('smtp.host'), $this->getParameter('smtp.port'), $this->getParameter('smtp.encryption')); $transport->setUsername($this->getParameter('smtp.username')); $transport->setPassword($this->getParameter('smtp.password')); $transport->setAuthMode($this->getParameter('smtp.auth_mode')); return $this->services['swiftmailer.transport'] = $transport; }
/** * @return \Fusio\Impl\Mail\MailerInterface */ public function getMailer() { if ($this->get('config')->get('psx_debug') === false) { $transport = \Swift_MailTransport::newInstance(); } else { $transport = \Swift_NullTransport::newInstance(); } return new Mailer($this->get('config_service'), $this->get('logger'), $transport); }
/** * @return \Swift_Mailer */ private function getSwiftMailerMock() { return $this->getMock("Swift_Mailer", array(), array(\Swift_NullTransport::newInstance())); }
public function finish(ContainerInterface $container) { //finishing locales $container->extend('locale.manager', function (LocaleManager $localeManager, ContainerInterface $container) { $locales = $container->getParameter('framework.locales'); foreach ($locales['locales'] as $id => $locale) { $localeObject = new Locale(); $localeObject->setId($id); $localeObject->setTitle($locale['title']); $localeObject->setActive($locale['active']); $localeObject->setCountry($locale['country']); $localeObject->setProperties($locale['properties']); $localeManager->addLocale($localeObject); } foreach ($locales['detectors'] as $detector) { $localeManager->addDetector($container[$detector]); } foreach ($locales['storage'] as $storage) { $localeManager->addStorage($container[$storage]); } $localeManager->setCurrent($locales['current']); return $localeManager; }); //entity audit $container['entity_audit.configuration'] = function (ContainerInterface $container) { $config = $container->getParameter('framework.doctrine_audit'); $configuration = new AuditConfiguration(); $configuration->setAuditedEntityClasses($config['entities']); $configuration->setGlobalIgnoreColumns($config['ignore_columns']); $configuration->setRevisionTableName('su_' . $configuration->getRevisionTableName()); $container->getEventDispatcher()->addListener(AuthController::TOKEN_CHANGE_EVENT, function () use($container, $configuration) { $context = $container->getSecurityContext(); if ($context->getToken() && $context->getToken()->getUser()) { $configuration->setCurrentUsername($context->getToken()->getUser()->getUsername()); } }); if (!$configuration->getCurrentUsername()) { $configuration->setCurrentUsername('anonymous'); } return $configuration; }; $container['entity_audit.manager'] = function (ContainerInterface $container) { $config = $container['entity_audit.configuration']; return new AuditManager($config); }; //finishing doctrine $doctrineConfig = $container->getParameter('framework.doctrine'); //let's believe that types are needed always foreach ($doctrineConfig['types'] as $definition) { list($name, $class) = $definition; Type::addType($name, $class); } foreach ($doctrineConfig['type_overrides'] as $definition) { list($name, $class) = $definition; Type::overrideType($name, $class); } foreach ($doctrineConfig['event_managers'] as $name => $managerDefinition) { $container['doctrine.event_managers.' . $name] = function (ContainerInterface $container) use($managerDefinition) { $manager = new EventManager(); foreach ($managerDefinition['subscribers'] as $id) { $manager->addEventSubscriber($container[$id]); } $container['entity_audit.manager']->registerEvents($manager); return $manager; }; } $application = $container->getApplication(); foreach ($doctrineConfig['configurations'] as $name => $configurationDefinition) { $container['doctrine.configurations.' . $name] = function (ContainerInterface $container) use($configurationDefinition, $application) { //loading package directories $packages = $application->getPackages(); $paths = array(); foreach ($packages as $package) { $entityDir = $application->locatePackageRoot($package) . DIRECTORY_SEPARATOR . 'Entity'; if (is_dir($entityDir)) { $paths[] = $entityDir; } } $configuration = Setup::createAnnotationMetadataConfiguration($paths, $container->getParameter('debug'), $container->getParameter('directories.cache') . DIRECTORY_SEPARATOR . 'doctrine'); if ($container->getParameter('debug')) { $logger = $container['logger.doctrine']; $container['doctrine.logger']->addLogger($logger); $configuration->setSQLLogger($container['doctrine.logger']); } //Foo:Bar -> \FooPackage\Entity\Bar aliases foreach ($packages as $package) { $class = get_class($package); $namespace = substr($class, 0, strrpos($class, '\\')) . '\\Entity'; $configuration->addEntityNamespace($application->resolveName($package), $namespace); } return $configuration; }; } foreach ($doctrineConfig['connections'] as $name => $connectionDefinition) { $container['doctrine.connections.' . $name] = function (ContainerInterface $container) use($connectionDefinition) { if ($connectionDefinition['driver'] != 'mysql') { throw new \Exception('No driver is supported currently but mysql'); } $connection = new Connection(array('host' => $connectionDefinition['host'], 'user' => $connectionDefinition['user'], 'password' => $connectionDefinition['password'], 'dbname' => $connectionDefinition['dbname'], 'charset' => $connectionDefinition['charset']), new PDOMySql\Driver(), $container['doctrine.configurations.' . $connectionDefinition['configuration']], $container['doctrine.event_managers.' . $connectionDefinition['event_manager']]); return $connection; }; } foreach ($doctrineConfig['entity_managers'] as $name => $entityManagerDefinition) { $container['doctrine.entity_managers.' . $name] = function (ContainerInterface $container) use($name, $entityManagerDefinition, $doctrineConfig) { $ormConfigurationName = $entityManagerDefinition['configuration']; $ormConfiguration = $container['doctrine.configurations.' . $ormConfigurationName]; $em = EntityManager::create($container['doctrine.connections.' . $entityManagerDefinition['connection']], $ormConfiguration, $container['doctrine.event_managers.' . $entityManagerDefinition['event_manager']]); // @DEV, remove $em->name = $name; foreach ($doctrineConfig['configurations'][$ormConfigurationName]['hydrators'] as $hydratorDefinition) { list($name, $class) = $hydratorDefinition; $reflection = new \ReflectionClass($class); $hydrator = $reflection->newInstanceArgs(array($em)); $ormConfiguration->addCustomHydrationMode($name, $hydrator); } return $em; }; } $container['doctrine.doctrine'] = function (ContainerInterface $container) use($doctrineConfig) { $connections = array(); foreach (array_keys($doctrineConfig['connections']) as $name) { $connections[$name] = 'doctrine.connections.' . $name; } $managers = array(); foreach (array_keys($doctrineConfig['entity_managers']) as $name) { $managers[$name] = 'doctrine.entity_managers.' . $name; } //todo: make default em/con configurable return new ManagerRegistry('supra.doctrine', $connections, $managers, $doctrineConfig['default_connection'], $doctrineConfig['default_entity_manager'], 'Doctrine\\ORM\\Proxy\\Proxy'); }; //sessions and HttpFoundation $sessionConfig = $container->getParameter('framework.session'); $container['http.session'] = function (ContainerInterface $container) use($sessionConfig) { if (PHP_SAPI == 'cli') { throw new \Exception('Sessions are not possible in CLI mode'); } $storage = $container[$sessionConfig['storage']]; $session = new Session($storage); $session->start(); $container['http.request']->setSession($session); return $session; }; //mailers $mailerConfig = $container->getParameter('framework.swiftmailer'); $container->setParameter('mailer.mailers', array_map(function ($value) { return 'mailer.mailers.' . $value; }, array_keys($mailerConfig['mailers']))); foreach ($mailerConfig['mailers'] as $id => $configurationDefinition) { $container['mailer.mailers.' . $id] = function (ContainerInterface $container) use($configurationDefinition) { switch ($configurationDefinition['transport']) { case 'smtp': $transport = \Swift_SmtpTransport::newInstance($configurationDefinition['params']['host'], $configurationDefinition['params']['port']); $transport->setUsername($configurationDefinition['params']['username']); $transport->setPassword($configurationDefinition['params']['password']); break; case 'mail': $transport = \Swift_MailTransport::newInstance(); if (isset($transport['params']['extra_params'])) { $transport->setExtraParams($transport['params']['extra_params']); } break; case 'sendmail': $transport = \Swift_SendmailTransport::newInstance(); if (isset($configurationDefinition['params']['command'])) { $transport->setCommand($configurationDefinition['params']['command']); } break; case 'null': $transport = \Swift_NullTransport::newInstance(); break; default: throw new \Exception(sprintf('Unknown mail transport [%s].', $configurationDefinition['transport'])); } return \Swift_Mailer::newInstance($transport); }; } $container['mailer.mailer'] = function (ContainerInterface $container) use($mailerConfig) { return $container['mailer.mailers.' . $mailerConfig['default']]; }; }
private function initializeSwiftmailerService() { $this->register(new SwiftmailerServiceProvider()); // set defaults $this['swiftmailer.options'] = $this->share(function () { $options = []; $options['transport'] = 'null'; $map = ['host' => 'SMTP_HOST', 'port' => 'SMTP_PORT', 'username' => 'SMTP_USERNAME', 'password' => 'SMTP_PASSWORD', 'encryption' => 'SMTP_ENCRYPTION', 'auth_mode' => 'SMTP_AUTH_MODE']; foreach ($map as $optname => $envname) { if (!isset($_ENV[$envname])) { continue; } $options['transport'] = 'smtp'; $options[$optname] = $_ENV[$envname]; } return $options; }); $this['swiftmailer.transport.mail'] = $this->share(function () { $transport = \Swift_MailTransport::newInstance(); return $transport; }); $this['swiftmailer.transport.sendmail'] = $this->share(function () { $transport = \Swift_SendmailTransport::newInstance(); return $transport; }); $this['swiftmailer.transport.null'] = $this->share(function () { $transport = \Swift_NullTransport::newInstance(); return $transport; }); $this['swiftmailer.transport'] = $this->extend('swiftmailer.transport', function ($transport) { if (isset($this['swiftmailer.options']) && isset($this['swiftmailer.options']['transport'])) { $service = 'swiftmailer.transport.' . strtolower(trim($this['swiftmailer.options']['transport'])); if (isset($this[$service])) { return $this[$service]; } } return $transport; }); }
protected function SendSynchronous(&$aIssues, $oLog = null) { $this->LoadConfig(); $sTransport = self::$m_oConfig->Get('email_transport'); switch ($sTransport) { case 'SMTP': $sHost = self::$m_oConfig->Get('email_transport_smtp.host'); $sPort = self::$m_oConfig->Get('email_transport_smtp.port'); $sEncryption = self::$m_oConfig->Get('email_transport_smtp.encryption'); $sUserName = self::$m_oConfig->Get('email_transport_smtp.username'); $sPassword = self::$m_oConfig->Get('email_transport_smtp.password'); $oTransport = Swift_SmtpTransport::newInstance($sHost, $sPort, $sEncryption); if (strlen($sUserName) > 0) { $oTransport->setUsername($sUserName); $oTransport->setPassword($sPassword); } break; case 'Null': $oTransport = Swift_NullTransport::newInstance(); break; case 'LogFile': $oTransport = Swift_LogFileTransport::newInstance(); $oTransport->setLogFile(APPROOT . 'log/mail.log'); break; case 'PHPMail': default: $oTransport = Swift_MailTransport::newInstance(); } $oMailer = Swift_Mailer::newInstance($oTransport); $aFailedRecipients = array(); $iSent = $oMailer->send($this->m_oMessage, $aFailedRecipients); if ($iSent === 0) { // Beware: it seems that $aFailedRecipients sometimes contains the recipients that actually received the message !!! IssueLog::Warning('Email sending failed: Some recipients were invalid, aFailedRecipients contains: ' . implode(', ', $aFailedRecipients)); $aIssues = array('Some recipients were invalid.'); return EMAIL_SEND_ERROR; } else { $aIssues = array(); return EMAIL_SEND_OK; } }