Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mailer] Delivery fails but actual SMTP response is not reported #40414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LuKePicci opened this issue Mar 8, 2021 · 17 comments
Closed

[Mailer] Delivery fails but actual SMTP response is not reported #40414

LuKePicci opened this issue Mar 8, 2021 · 17 comments

Comments

@LuKePicci
Copy link

LuKePicci commented Mar 8, 2021

Symfony version(s) affected: 5.2

Description
Proper duplicate of #32148 Look at there for background. Actual issue is that the SMTP server gives a non-empty error/unexpected response but symfony does not catch it properly and outputs this misleading error:

request.CRITICAL: Uncaught PHP Exception Symfony\Component\Mailer\Exception\TransportException: "Expected response code "250" but got an empty response." at /home/site/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php line 300 {"exception":"[object] (Symfony\Component\Mailer\Exception\TransportException(code: 0): Expected response code "250" but got an empty response. at /home/site/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:300)"} []

while the real one is different and certainly not an empty response. In my peculiar case the error was:

421 4.7.0 Try again later, closing connection. (EHLO) n18sm285960wrm.12 - gsmtp

Please note the reason for the above SMTP message to occur is out of scope here and I already managed to workaround it.
You should consider this issue as solved as soon as you get that 421 message catched and reported in php logs.

How to reproduce
A sufficient condition to reproduce is to use symfony mailer with this DSN: smtp://smtp-relay.gmail.com:587
The SMTP server will respond with 421 error message because of another symfony bug which makes symfony 5.2 using a bad default local_domain ( [127.0.0.1] in my case ) in EHLO command.
You don't need to subscribe or configure any gsuite smtp relay for the bug to reproduce.

Additional context
How to debug:

    /**
     * Runs a command against the stream, expecting the given response codes.
     *
     * @param int[] $codes
     *
     * @return string The server response
     *
     * @throws TransportException when an invalid response if received
     *
     * @internal
     */
    public function executeCommand(string $command, array $codes): string
    {
        $this->stream->write($command);
dump($command);
        $response = $this->getFullResponse();
dump($response);
        $this->assertResponseCode($response, $codes);

        return $response;
    }
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@LuKePicci
Copy link
Author

LuKePicci commented Sep 10, 2021

Sure it is. Look for my workaround at #32148

@carsonbot carsonbot removed the Stalled label Sep 10, 2021
@xabbuh
Copy link
Member

xabbuh commented Sep 21, 2021

@LuKePicci Would you like to give this a try?

@LuKePicci
Copy link
Author

Sorry, I didn't get what you mean with "this"

@xabbuh
Copy link
Member

xabbuh commented Sep 21, 2021

I mean trying to work on a fix for this issue.

@scorpioniz
Copy link

scorpioniz commented Nov 25, 2021

Still happens with SF 5.3.10 :/ I using sendgrid transport (dont know if it's helping). And happens only then using monolog error to send to email :) other ways (never noticed) doesn't happen.

@xabbuh
Copy link
Member

xabbuh commented Nov 25, 2021

@scorpioniz Would you like to try working on a fix for this?

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@LuKePicci
Copy link
Author

Ofc it is

@carsonbot carsonbot removed the Stalled label May 26, 2022
@xabbuh
Copy link
Member

xabbuh commented May 26, 2022

Well, this issue won't magically resolve itself. Someone would actually have to work on it.

@fabpot
Copy link
Member

fabpot commented Jul 27, 2022

Just tried the reproducer, but that does not work for me, I get: Expected response code "250" but got code "550", with message "550-5.7.0 Mail relay denied [2a01:e34:ee66:4390:8210:a0ac:868f:4c56]. Invalid

@LuKePicci
Copy link
Author

In my case I think the ipv6 was the local one ::1

I suggest you try repro from a free instance of azure app service like mine.

@fabpot
Copy link
Member

fabpot commented Jul 29, 2022

I don't have an Azure account. I'm willing to help fix this one but I cannot do anything without a reproducer.

@LuKePicci
Copy link
Author

LuKePicci commented Jul 29, 2022

ok, I reverted my workaround:

[2022-07-29T14:10:45.036019+00:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Mailer\Exception\TransportException: "Expected response code "250" but got an empty response." at /home/site/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php line 299 {"exception":"[object] (Symfony\\Component\\Mailer\\Exception\\TransportException(code: 0): Expected response code \"250\" but got an empty response. at /home/site/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:299)"} []

without an Azure App Service instance, your best option to repro is to manually giving by local_domain the bad [::1] value which makes Google SMTP screaming:

MAILER_DSN=smtp://smtp-relay.gmail.com:587/?local_domain=[::!]

@fabpot
Copy link
Member

fabpot commented Aug 1, 2022

@LuKePicci Thank you, I was able to reproduce and I've submitted a PR to fix this at #47142. Can you confirm if fixes this issue for you as well?

@LuKePicci
Copy link
Author

I'll test asap on my existing environment. Is it fine if I simply hotpatch the related files and refresh the send email page? Would I need to rebuild cache or similar things?

@fabpot
Copy link
Member

fabpot commented Aug 1, 2022

Hot-patching should be enough.

nicolas-grekas added a commit that referenced this issue Aug 2, 2022
This PR was merged into the 4.4 branch.

Discussion
----------

[Mailer] Fix error message in case of an STMP error

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #40414 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | n/a

Better exception messages are generally done in the "main" branch, but this one is quite nasty as it masks the actual error message from the SMTP server, so I think it deserves to be merged in 4.4.

Commits
-------

aee6d08 [Mailer] Fix error message in case of an STMP error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants