Skip to content

Update AbstractTransport.php #37313

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
wants to merge 1 commit into from
Closed

Update AbstractTransport.php #37313

wants to merge 1 commit into from

Conversation

ThomasLandauer
Copy link
Contributor

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

Removing ? from return type.
According to line 66, a SentMessage is returned in any case, isn't it?

If you agree, this change should be reflected in extending classes as well, e.g. https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php#L129

Question: What's the recommended way to check if the mail has been sent successfully? I didn't find anything better than $sentMessage->getDebug() yet...

Removing ? from return type.
According to line 66, a SentMessage is returned in any case, isn't it?

If you agree, this change should be reflected in extending classes as well, e.g. https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php#L129

Question: What's the recommended way to check if the mail has been sent successfully? I didn't find anything better than $sentMessage->getDebug() yet...
@nicolas-grekas
Copy link
Member

👎 this change breaks child classes that want to return null.

@ThomasLandauer
Copy link
Contributor Author

Well, OK, but I couldn't find any such child class. Most Transports just do parent::send(), e.g. https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php#L132

However, the answer to my main question (check if message was sent successfully) seems to be to wrap the ->send() in a try and catch a Symfony\Component\Mailer\Exception\TransportException, right? => Should I go ahead and come up with a PR to explain this at https://symfony.com/doc/4.4/mailer.html ?

@fabpot
Copy link
Member

fabpot commented Jun 24, 2020

You should catch the interface instead: Symfony\Component\Mailer\Exception\TransportExceptionInterface. Closing this PR and indeed, a fix in the docs would be great. Thank you.

@fabpot fabpot closed this Jun 24, 2020
ThomasLandauer added a commit to ThomasLandauer/symfony-docs that referenced this pull request Jun 24, 2020
Follow-up of symfony/symfony#37313 (comment)
Explaining how to "verify" successful delivery by catching the TransportException
@ThomasLandauer
Copy link
Contributor Author

Sure, see symfony/symfony-docs#13895

@ThomasLandauer ThomasLandauer deleted the patch-1 branch June 24, 2020 11:02
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Jun 26, 2020
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

Update mailer.rst

Follow-up of symfony/symfony#37313 (comment)

Explaining how to "verify" successful delivery by catching the TransportException

Commits
-------

939d3cd Update mailer.rst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants