Reputation: 1002
I would like to know more about spooling emails in swiftmailer. In fact, I use swiftmailer with spool type memory:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
port: "%mailer_port%"
encryption: "%mailer_encryption%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I send email like this in a symfony method called in AJAX:
public function ajaxAction(Request $request)
{
if ($request->isXMLHttpRequest()) {
$data = $request->request->get('contact');
$message = \Swift_Message::newInstance()
->setSubject('Contact site')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody(
$this->renderView(
'MyAppMyBundle:Emails:contact.html.twig',
array('name' => $data['name'], 'mail' => $data['mail'], 'message' => $data['message'])
),
'text/html'
);
$this->get('mailer')->send($message);
return new Response('Mail sent', 200);
}
}
It results in a very time consuming AJAX call:
I expected that the spool make the sent of emails after the kernel.terminate event but it seems that it is done in the kernel.terminate. So the AJAX call is very long and i dont take expected advantages of spooling emails.
Can you help me?
Upvotes: 3
Views: 4846
Reputation: 4107
As explained in the Symfony Docs, the memory-based spool sends the email before the kernel.terminate
event.
In this case, you probably want to use file-based spools, as explained in How to Spool Emails with Symfony article.
Upvotes: 2