2012-09-23 32 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); 

希望它可以幫助

相關問題