如何解决 Swift_TransportException Connection to ssl Timed Out 错误? [英] How to solve Swift_TransportException Connection to ssl Timed Out error?

查看:47
本文介绍了如何解决 Swift_TransportException Connection to ssl Timed Out 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Yii 发送电子邮件时遇到问题,问题是有时会导致 ssl 超时,但有时邮件发送进展顺利.

错误是这样的

 Swift_TransportException连接到 ssl://in-v3.mailjet.com:465 超时

这是错误图片

看了一些文章,好像是因为socket超时了,应该重新启动socket.

这是我读过的文章.

swiftmailer 和 Yii2 不工作 10 分之一时间

如何在 SwiftMailer 中关闭 Smtp 连接

这是我在 common\config\main-local.php

中的配置

'mail' =>['类' =>'yii\swiftmailer\Mailer','视图路径' =>'@后端/邮件','useFileTransport' =>错误的,'运输' =>['类' =>'Swift_SmtpTransport','主机' =>'in-v3.mailjet.com','用户名' =>'我的用户名','密码' =>'myS3cr3tP4ss','端口' =>'465','加密' =>'ssl',],],

这是我在控制器中发送电子邮件的方式

$message = Yii::$app->mail->compose();if (Yii::$app->user->isGuest) {$message->setFrom('from@domain.com');} 别的 {$message->setFrom(Yii::$app->user->identity->email);}$message->setTo(Yii::$app->params['adminEmail'])->setFrom(Yii::$app->params['adminEmail'])->setTo($model->email)->setSubject('重置密码')->setHtmlBody($this->renderAjax('//email/_content',['content' =>'电子邮件内容在这里']))->发送();返回 $this->render('confirmation_sent');

如何停止和开始与我的上述代码的连接?

我已经把这段代码正好放在$message

之前

if (Yii::$app->mailer->getTransport()->isStarted()) {Yii::$app->mailer->getTransport()->stop();}Yii::$app->mailer->getTransport()->start();

但它有时仍然显示SSL time out.

我向mailjet询问了这个问题,得到了这个答复

您好,感谢您的回复.好的,请尝试使用带有 SSL 的端口 443 或:25,80、2525 没有加密,587 和 588 带有 TLS.让我知道它是否有效.

已经尝试使用给定加密的所有端口但它保持不变,有时我遇到Timed Out

更新

使用 try catch 给我 使用 3 个可能的身份验证器 1 有时无法使用用户名a3027c30a1c1f6f60d2f9d7813360b46"在 SMTP 服务器上进行身份验证.

使用 try catch 也给我 连接到 ssl://in-v3.mailjet.com:465 超时,它有时会显示.

这是我从我们的服务器到 mailjet 的跟踪路由

traceroute to in-v3.mailjet.com (37.59.74.234),最多 30 跳,60 字节数据包1 个网关 (123.231.250.129) 1.084 毫秒 1.114 毫秒 3.485 毫秒2 36.37.76.84 (36.37.76.84) 17.495 毫秒 17.497 毫秒 36.37.76.70 (36.37.76.70) 1 7.215 毫秒3 36.37.77.68 (36.37.77.68) 30.878 毫秒 36.37.77.14 (36.37.77.14) 30.322 毫秒 3 2.661 毫秒4 36.37.77.39 (36.37.77.39) 33.103 毫秒 * *5 * * *6 * * *7 * * gblx.as3549.ny.us (213.251.130.102) 362.627 毫秒8 * * *9 * * *10 * * *11 * * *12 * * *13 * * *14 * * *15 * * *16 * * *17 * * *18 * * *19 * * *20 * * *21 * * *22 * * *23 * * *24 * * *25 * * *26 * * *27 * * *28 * * *29 * * *30 * * *

这是因为不同的 Yii::$app->mailer 开始停止套接字和 Yii::$app->mail 发送电子邮件吗?>

我对这些错误是否正确,因为 ssl 套接字已停止?也请解释一下这个错误是怎么出现的.

提前致谢.

解决方案

您有一个错误,因为它无法连接到 smtp 并且尝试的时间已过.尝试更改端口和加密,也许这会对您有所帮助,但我不确定.这要看你的n-v3.mailjet.com,他需要什么设置,我不知道.

'mail' =>['类' =>'yii\swiftmailer\Mailer','视图路径' =>'@后端/邮件','useFileTransport' =>错误的,'运输' =>['类' =>'Swift_SmtpTransport','主机' =>'in-v3.mailjet.com','用户名' =>'我的用户名','密码' =>'myS3cr3tP4ss','端口' =>'587','加密' =>'ssl',],],

I have a problem send email using Yii, the problem is sometime it result in ssl timeout, but some time mail send is going well.

The error says something like this

 Swift_TransportException

 Connection to ssl://in-v3.mailjet.com:465 Timed Out

Here is the error image

After reading some article, it's looks like because socket is timeout so it should start socket again.

Here is my article that I read.

swiftmailer and Yii2 not working 1 out of 10 time

How to close Smtp connection in SwiftMailer

Here is my config in common\config\main-local.php

'mail' => [
  'class' => 'yii\swiftmailer\Mailer',
  'viewPath' => '@backend/mail',
  'useFileTransport' => false,
  'transport' => [
      'class' => 'Swift_SmtpTransport',
      'host' => 'in-v3.mailjet.com',
      'username' => 'myUserName',
      'password' => 'myS3cr3tP4ss',
      'port' => '465',
    'encryption' => 'ssl',
  ],
],

Here is how I send email in my controller

$message = Yii::$app->mail->compose();
if (Yii::$app->user->isGuest) {
  $message->setFrom('from@domain.com');
} else {
  $message->setFrom(Yii::$app->user->identity->email);
}
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo($model->email)
->setSubject('Reset Password')
->setHtmlBody($this->renderAjax('//email/_content',['content' => 'email content goes here']))
->send();
return $this->render('confirmation_sent');

How I can stop and start connection with my above code?

I have already put this code exactly before $message

if (Yii::$app->mailer->getTransport()->isStarted()) {
    Yii::$app->mailer->getTransport()->stop();
}
Yii::$app->mailer->getTransport()->start();

But it still show SSL time out sometimes.

I ask about this problem to mailjet, and got this response

Hi, Thank you for your reply.
Ok, please try with port 443 with SSL or: 25,80, 2525 with no encryption, 587 and 588 with TLS.
Let me know if it works.

Already try all the port with given encryption but it's remain the same, sometime I meet Timed Out

UPDATED

Using try catch give me Failed to authenticate on SMTP server with username "a3027c30a1c1f6f60d2f9d7813360b46" using 3 possible authenticators1 some times.

Using try catch give me Connection to ssl://in-v3.mailjet.com:465 Timed Out too, it show sometime.

Here is my traceroute from our server to mailjet

traceroute to in-v3.mailjet.com (37.59.74.234), 30 hops max, 60 byte packets
 1  gateway (123.231.250.129)  1.084 ms  1.114 ms  3.485 ms
 2  36.37.76.84 (36.37.76.84)  17.495 ms  17.497 ms 36.37.76.70 (36.37.76.70)  1                                                                                                                                                 7.215 ms
 3  36.37.77.68 (36.37.77.68)  30.878 ms 36.37.77.14 (36.37.77.14)  30.322 ms  3                                                                                                                                                 2.661 ms
 4  36.37.77.39 (36.37.77.39)  33.103 ms * *
 5  * * *
 6  * * *
 7  * * gblx.as3549.ny.us (213.251.130.102)  362.627 ms
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *

Is this because different Yii::$app->mailer to start stop socket and Yii::$app->mail to send email?

Am I right these error because ssl socket is stopped? Please explain me too how come this error appear.

Thanks in advance.

解决方案

You have an error because it can not connect to the smtp and the time for attempts is over. Try to change the port and encryption, maybe this will help you but I'm not sure. It depends on your n-v3.mailjet.com, what settings he needs, I do not know.

'mail' => [
  'class' => 'yii\swiftmailer\Mailer',
  'viewPath' => '@backend/mail',
  'useFileTransport' => false,
  'transport' => [
      'class' => 'Swift_SmtpTransport',
      'host' => 'in-v3.mailjet.com',
      'username' => 'myUserName',
      'password' => 'myS3cr3tP4ss',
      'port' => '587',
      'encryption' => 'ssl',
  ],
],

这篇关于如何解决 Swift_TransportException Connection to ssl Timed Out 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆