使用 yii2 的 Switfmailer 的静态配置不会发送邮件



使用以下静态配置将导致类似这样的异常。

Swift_TransportException: Failed to authenticate on SMTP server with username "thomas.kipp@eisvogel-online-software.de" using 3 possible authenticators in

使用邮件客户端发送邮件不会有任何问题,所以以下参数基本上是正确的

'mailer' => [
'class' => 'yiiswiftmailerMailer',
'viewPath' => '@common/mail',
'useFileTransport' => false, //set this property to true to send mails to mail emulator. Set this property to false to send real mails.              
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.strato.de',
'username' => 'thomas.kipp@eisvogel-online-software.de',
'password' => 'top secret',
'port' => '587',
'encryption' => 'tls',
],
],

这种配置有什么问题?以下配置:

'mailer' => [
'class' => 'yiiswiftmailerMailer',
'viewPath' => '@common/mail',
'useFileTransport' => false, //set this property to true to send mails to mail emulator. Set this property to false to send real mails.              
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'tklustig.thomas@gmail.com',
'password' => 'top secret',
'port' => '587',
'encryption' => 'tls',
],
],

会抛出这样的错误:

Swift_TransportException: Connection could not be established with host smtp.gmail.com [Connection timed out #145] in

gmx也是如此。我不能再使用Swiftmailer发送邮件了。我能做什么?

我认为谷歌的smtp在不同的端口和加密类型上工作。

'mailer' => [
'class' => 'yiiswiftmailerMailer',
'viewPath' => '@common/mail',
'useFileTransport' => false,             
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username',
'password' => 'password',
'port' => '465',
'encryption' => 'ssl',
],
],

我认为这应该能解决你的问题。

顺便说一句。我不明白为什么你的tls连接不起作用。尝试使用ssl。

最新更新