Symfony 邮件程序:消息发送之间的 Swift_TransportException

发布于 2024-11-17 23:46:28 字数 592 浏览 3 评论 0原文

在我目前正在工作的当前项目中,我有一个 symfony 任务,该任务将一些大量数据插入数据库并运行至少半个小时。 当任务开始时,邮件通知已正确发送,问题是在任务执行时我们无法发送另一封邮件来通知处理结束。

邮件程序工厂当前配置了假脱机传递策略,但在这种特定情况下,我们希望使用 sendNextImmediately() 方法立即触发通知。

我收到异常:

[Swift_TransportException]
预期响应代码为 250,但收到代码“451”,并显示消息“451 4.4.2 超时 - 关闭连接。74sm1186065wem.17” ”

以及 php 日志文件中的流动错误:

警告:fwrite():SSL:第 209 行 /var/www/project/lib/vendor/symfony/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php 中的管道损坏

有人可以提供帮助吗? 有什么方法可以刷新 symfony 邮件程序以建立新连接吗?

On a current project which I'm currently working, i have a symfony task that runs some mass data insertion to database and runs it for at least half an hour.
When the task starts a mail notification is sent correctly, the problem is that at the of the task execution we can't send another mail to notify about the end of processing.

The mailer factory is currently configured with the spool delivery strategy but, in this specific situation, we desire to fire a notification immediately, using the sendNextImmediately() method.

I'm are getting the exception:

[Swift_TransportException]
Expected response code 250 but got code "451", with message "451 4.4.2 Timeout - closing connection. 74sm1186065wem.17
"

and the flowing error on php log file:

Warning: fwrite(): SSL: Broken pipe in /var/www/project/lib/vendor/symfony/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php on line 209

Can anyone give some help?
Is there any way that i can perhaps refresh symfony mailer to establish a new connection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紫罗兰の梦幻 2024-11-24 23:46:29

对于 Symfony1 用户

我的猜测是连接保持时间太长(根本没有任何活动),导致 ssl 连接超时。

目前,可以通过在发送第二条消息之前停止 Swift_Transport 实例并再次显式启动它来解决该问题。

这是代码:

$this->getMailer()->getRealtimeTransport()->stop();
$this->getMailer()->getRealtimeTransport()->start();
$this->getMailer()->sendNextImmediately()->send($message);

For Symfony1 Users

My guess was that the connection was being hold for too long (with no activity at all), causing an ssl connection timeout.

For now, the problem can be solved by stopping the Swift_Transport instance and starting it again explicitly, just before sending the second message.

Here is the code:

$this->getMailer()->getRealtimeTransport()->stop();
$this->getMailer()->getRealtimeTransport()->start();
$this->getMailer()->sendNextImmediately()->send($message);
命硬 2024-11-24 23:46:29

我遇到了完全相同的问题,上述解决方案非常有帮助,但有一件事我必须做不同的事情:顺序。

$this->getMailer()->sendNextImmediately()->send($message);
$this->getMailer()->getRealtimeTransport()->stop();

如果我在发送消息之前尝试停止传输(连接超时已经挂起),它对我不起作用。另外,您不需要运行 getRealtimeTransport()->start() - 它会自动启动。

I had exactly the same problem and above solutions were very helpful, but there is one thing I had to do differently: order.

$this->getMailer()->sendNextImmediately()->send($message);
$this->getMailer()->getRealtimeTransport()->stop();

It didn't worked for me if I tried to stop Transport before sending message (connection timeout was already hanging). Also You don't need to run getRealtimeTransport()->start() - it will be started automatically.

香草可樂 2024-11-24 23:46:28

在做Symfony2项目时,我也遇到过这个失败。我们使用的是永久运行的 php 脚本,这会产生错误。

我们发现以下代码可以完成这项工作:

private function sendEmailMessage($renderedTemplate, $subject, $toEmail)
    {
        $mailer = $this->getContainer()->get('mailer');
        /* @var $mailer \Swift_Mailer */
        if(!$mailer->getTransport()->isStarted()){
            $mailer->getTransport()->start();
        }
        $sendException = null;
        /* @var $message \Swift_Message */
        $message = \Swift_Message::newInstance()
            ->setSubject($subject)
            ->setFrom($this->getContainer()->getParameter('email_from'))
            ->setTo($toEmail)
            ->setBody($renderedTemplate);


        $mailer->send($message);
        $mailer->getTransport()->stop();
        //throw $sendException;
    }

Doing a Symfony2 project, I ran across this failure too. We were using a permanently running php script, which produced the error.

We figured out that following code does the job:

private function sendEmailMessage($renderedTemplate, $subject, $toEmail)
    {
        $mailer = $this->getContainer()->get('mailer');
        /* @var $mailer \Swift_Mailer */
        if(!$mailer->getTransport()->isStarted()){
            $mailer->getTransport()->start();
        }
        $sendException = null;
        /* @var $message \Swift_Message */
        $message = \Swift_Message::newInstance()
            ->setSubject($subject)
            ->setFrom($this->getContainer()->getParameter('email_from'))
            ->setTo($toEmail)
            ->setBody($renderedTemplate);


        $mailer->send($message);
        $mailer->getTransport()->stop();
        //throw $sendException;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文