Symfony swiftmailer 内存假脱机

Symfony swiftmailer memory spool

我想了解更多有关在 swiftmailer 中假脱机电子邮件的信息。 事实上,我使用带假脱机类型内存的 swiftmailer:

swiftmailer:
    transport:          "%mailer_transport%"
    host:               "%mailer_host%"
    port:               "%mailer_port%"
    encryption:         "%mailer_encryption%"
    username:           "%mailer_user%"
    password:           "%mailer_password%"
    spool:              { type: memory }

我在 AJAX:

中调用的 symfony 方法中发送这样的电子邮件
public function ajaxAction(Request $request)
{
    if ($request->isXMLHttpRequest()) {
            $data = $request->request->get('contact');
            $message = \Swift_Message::newInstance()
                ->setSubject('Contact site')
                ->setFrom('postmaster@mywebsite.com')
                ->setTo('contact@mywebsite.com')
                ->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);
     }
}

它导致非常耗时的 AJAX 调用: 我预计假脱机会在 kernel.terminate 事件之后发送电子邮件,但它似乎是在 kernel.terminate 中完成的。所以 AJAX 调用很长,我没有利用假脱机电子邮件的预期优势。 你能帮帮我吗?

如 Symfony 文档中所述,基于内存的假脱机在 kernel.terminate 事件之前发送电子邮件。

在这种情况下,您可能希望使用基于文件的假脱机,如 How to Spool Emails with Symfony 文章中所述。