Yii2-swiftmailer发邮件失败报fwrite(): SSL: Broken pipe
2018-10-13 10:37
651 查看
个人博客原文地址:http://www.lampnick.com/php/706
Yii2版本:2.0.3
SwiftMail版本:v5.3.1
使用定时任务发邮件时,由于swiftmailer长时间运行没有关闭transport,造成SSL连接出错。
报错1:
exception 'Swift_TransportException' with message 'Expected response code 250 but got code "", with message ""' in vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383
报错2:
exception 'yii\base\ErrorException' with message 'fwrite(): SSL: Broken pipe' in vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:232
解决方案:
1.修改vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php:90
public function send(Swift_Mime_Message $message, &$failedRecipients = null) { $failedRecipients = (array) $failedRecipients; if (!$this->_transport->isStarted()) { $this->_transport->start(); } $sent = 0; try { $sent = $this->_transport->send($message, $failedRecipients); } catch (Swift_RfcComplianceException $e) { foreach ($message->getTo() as $address => $name) { $failedRecipients[] = $address; } } catch (\Exception $exception) { $this->_transport->stop(); sleep(10); throw $exception; } finally { $this->_transport->stop(); sleep(1); } return $sent; }
2.在调用发送邮件处进行失败重试
/** * @return bool */ private function sendEmail() { $tmpPath = \Yii::$app->getRuntimePath() . '/logs/'; $tmpFilePath = File::downFileForNotExist($tmpPath, $this->filePath); $result = \Yii::$app->mailer->compose() ->setTo($this->emailTo) ->setFrom(['nick@lampnick.com' => 'lampNick']) ->setSubject($this->subject) ->setTextBody($this->body) ->attach($tmpFilePath) ->send(); @unlink($tmpFilePath); return $result; } /** * 尝试发邮件 */ private function trySendMail() { $tryCount = self::TRY_COUNT; while ($tryCount > 0) { try { $sendResult = $this->sendEmail(); if (!$sendResult) { throw new SendMailAsynException; } return; } catch (\Exception $e) { $tryCount--; \Yii::error("swiftMailer发邮件失败,重试发送,失败原因是:" . (string)$e); \Yii::getLogger()->flush(true); $this->trySendMail(); } } }阅读更多
相关文章推荐
- 用qq邮箱做服务器发邮件失败,530 A secure connection is requiered(such as ssl)后解决方案如下
- 邮件发送失败( connection failed,Can't send command to SMTP host,Broken pipe)
- CentOS 7 下sendEmail发邮件失败,提示invalid SSL_version specified at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 415.
- ubuntu mail 发邮件 失败
- Mysql Broken Pipe,长久折磨的结痂
- 用spring发邮件验证失败问题2
- 终极解决:iOS 与 Java 服务器之间 SSL 握手失败的解决:Cipher Suites
- Ubuntu 12.04 64bit 配置完android 5.0编译环境后出现“could not write bytes: Broken pipe.”而无法进入输入帐号密码的登陆界面
- java发邮件失败
- android 图片上传图片 报Socket: Broken pipe
- java.net.SocketException: Broken pipe 异常可能的原因
- RedHat 6.4 安装WAS 7.0 启动失败com.ibm.websphere.ssl.SSLException
- JDK1.8下qq邮箱发邮件出现握手失败
- 解决ssh的"Write failed: Broken pipe"问题
- 【Android问题】解决 Android SDK下载和更新失败“Connection to https://dl-ssl.google.com refused”的问题
- Python提示[Errno 32] Broken pipe 导致线程crash错误
- Xcode错误:putpkt: write failed, broken pipe解决办法
- Program received signal SIGPIPE, Broken pipe
- Socket 编程时候遇到的Broken pipe问题
- 【翻译自mos文章】当/var/tmp文件夹被remove掉之后,GI crash,并启动失败,原因是ohasd can not create named pipe