2012-09-23 34 views

回答

1

嗯......你实际上可以在你的捆绑包中获得邮件服务,并以你需要的方式配置它们。刚拿到运输实例,配置它的处理程序,并与注射配置transport没有创造新的mailer实例:

$transport = $this->get('swiftmailer.transport'); 
    $transport->setHost('smtp.gmail.com'); 
    $transport->setEncryption('ssl'); 

    $handlers = $transport->getExtensionHandlers(); 

    $handler = $handlers[0]; 
    $handler->setUsername(''); 
    $handler->setPassword(''); 
    $handler->setAuthMode('login'); 

    $mailer = \Swift_Mailer::newInstance($transport); 

我设置上述假设你想使用gmail运输某些属性。在vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php有这个运输简单检查:

//... 
    } elseif ('gmail' === $config['transport']) { 
     $config['encryption'] = 'ssl'; 
     $config['auth_mode'] = 'login'; 
     $config['host'] = 'smtp.gmail.com'; 
     $transport = 'smtp'; 
    } else { 
    //... 

您可以尝试通过获取其容器配置spool(你获得mailer服务之前做到这一点):

$this->getContainer() 
    ->setParameter('swiftmailer.spool.file.path, '%kernel.cache_dir%/swiftmailer/spool'); 

但这个文件路径应该默认使用。你只需要启用后台打印:

$this->getContainer()->setParameter('swiftmailer.spool.enabled', true); 

antiflood可以用类似的方式进行配置:

$this->getContainer()->setParameter('swiftmailer.plugin.antiflood.threshold', 99); 
$this->getContainer()->setParameter('swiftmailer.plugin.antiflood.sleep', 0); 

希望它可以帮助

相关问题