首页  >  问答  >  正文

标题重写为:Symfony\Component\Mailer\Exception\TransportException:预期的响应代码为"250",但收到了空响应

我正在使用 Google Workspace SMTP 中继服务从我的 Laravel 应用发送电子邮件。它已经运行良好一年多了,但我不确定到底是什么阻止了它的运行。 当我尝试发送电子邮件时,出现以下错误:

>>> IlluminateSupportFacadesMail::to('myemail@gmail.com')->send(new AppMailCourseEnrolmentEmail($user, AppCourse::first()));

// The error
SymfonyComponentMailerExceptionTransportException with message 'Expected response code "250" but got an empty response.'

我怀疑这与我从 Laravel 8 升级到 Laravel 9 有关,但不确定如何修复它。

我的mail.php

'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
        ],

我的邮件配置

MAIL_DRIVER=smtp
MAIL_HOST=smtp-relay.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=TLS
MAIL_FROM_NAME="My Name"
MAIL_FROM_ADDRESS=myaddress@workspace.com

我通过 IP 进行身份验证,因此不需要密码和用户名字段

我的 GSuite Gmail 路由配置


注意 在上面的配置中,我尝试检查 TLS 并将允许的发件人更改为“仅我域中的注册应用程序用户”,但问题仍然存在。

我尝试过来自

的建议
  1. https://laracasts.com/discuss/channels/laravel/laravel-swift-mailer-exception-expected-response-code-250-but-got-an-empty-response-using-gmail- smtp 中继数据库队列驱动程序

  2. Laravel 9 - Infomaniak:预期响应代码“250”,但收到代码“550”,并显示消息“550 5.7.1 发件人不匹配”

  3. https://stackoverflow.com/a/43283422/11752623

  4. https://www.cubebackup.com/blog/how-to-use-google-smtp-service-to-send-emails-for-free/ 方法 3

所有这些都没有成功。感谢您帮助解决此问题。

P粉350036783P粉350036783324 天前643

全部回复(1)我来回复

  • P粉221046425

    P粉2210464252023-11-04 15:51:18

    找到了解决办法, 我在assertResponseCode方法下访问了vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php。我回应了显示以下内容的回复:

    421 4.7.0 Try again later, closing connection. (EHLO) r29-200a50c01d0000xxxxxxxxxxxx87edb.28 - gsmtp

    有关该错误的更多详细信息,请参阅 Google 文档

    问题在于 Swift Mailer 使用 127.0.0.1 作为发送 Gmail 未知邮件的域。

    因此,解决方案是在 config/mail.php 文件中设置我的域名

    
            'smtp' => [
                'transport' => 'smtp',
                'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
                'port' => env('MAIL_PORT', 587),
                'encryption' => env('MAIL_ENCRYPTION', 'tls'),
                'username' => env('MAIL_USERNAME'),
                'password' => env('MAIL_PASSWORD'),
                'timeout' => null,
                'local_domain' => env('MAIL_EHLO_DOMAIN', 'mydomain.com')//this line here
            ],
    

    更多信息:

    1. https://insights.rytass.com/gmail-smtp-relay-421-4-7-0-try-again-later- opening-connection-ehlo-cfcdac3cf9c7
    2. https://serverfault .com/questions/929559/postfix-error-421-4-7-0-try-again-later- opening-connection-ehlo

    回复
    0
  • 取消回复