我无法让 SwiftMailer 发送 Symfony2 命令

I can't get SwiftMailer to send in a Symfony2 Command

我正在尝试设置一个命令来发送警告电子邮件,但我无法让 SwiftMailer 实际发送它们。

我阅读了一些关于清除后台处理程序的帖子,但我仍然没有看到发送到 Postfix 的电子邮件。

电子邮件确实在控制器中工作,我收到了它们。所以我知道 Postfix 本身在工作,而 SwiftMailer 在 Controller 中工作。

这是我的执行函数

protected function execute(InputInterface $input, OutputInterface $output)
{
    $container = $this->getContainer();
    $entityManager = $container->get('doctrine')->getManager();
    $mailer = $container->get('mailer');
    $transport = $container->get('swiftmailer.transport.real');


    $things = $container->get('mike.stuff.service')->getThings();
    foreach ($things as $thing) {

            $recipients = array($thing->getPerson()->getEmail() => $thing->getPerson()->getName());

            $message = sprintf('Hello %s'.PHP_EOL.PHP_EOL.'This is an alert regarding %s',
                    $thing->getPerson()->getName(),
                    $thing->getReferenceNumber());

            $email = \Swift_Message::newInstance()
                ->setSubject('Alert')
                ->setFrom('noreply@mydomain.com')
                ->setTo($recipients)
                ->setBody($message);
            $mailer->send($email);
        }
    }

    // Flush the mailer transport
    $spool = $mailer->getTransport()->getSpool();
    $sent = $spool->flushQueue($transport);

    echo 'I sent ' . $sent;
}

当我 运行 命令输出是 "I sent 1" 时,看起来它成功了。但是 /var/log/mail.log 没有添加任何内容(所以我当然没有收到电子邮件)。

默认情况下,dev 环境中的命令是 运行,因此如果您对 devprod 环境有不同的配置,则需要 运行 您在 prod 环境中的命令(使用 --env=prod