You can create a kernel.request
event listener, inject swiftmailer.transport.real
and set smpt info e.g
Listener class
namespace Namespace\Of\YourListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class YourListener implements EventSubscriberInterface
{
/**
* @var Swift_Transport_EsmtpTransport
*/
private $transport;
/**
* @var Doctrine\ORM\EntityManager
*/
private $em;
public function __construct($transport, $em)
{
$this->transport = $transport;
$this->em = $em;
}
public function onKernelRequest(GetResponseEvent $event)
{
//fetch info from db
$this->transport->setHost("host");
$this->transport->setPort("port");
$this->transport->setUserName("username");
$this->transport->setPassword("pass");
}
static public function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array('onKernelRequest', 0)
);
}
}
Service decleration,
your_listener:
class: FQCN\Of\YourListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
arguments: [@swiftmailer.transport.real, @doctrine.orm.entity_manager]