Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Don't know how to handle the case when connection is refused by a mail server. #1269

Closed
0fca opened this issue Mar 31, 2020 · 6 comments
Closed

Comments

@0fca
Copy link

0fca commented Mar 31, 2020

Q A
Bug report? yes
Feature request? no
RFC? no
How used? Symfony
Swiftmailer version 3.0
PHP version 7.3.16

Observed behaviour

My code just uses: send($message, $errors);
There are 3 mail addresses set as receipents, correctly set to headers as "To".
Each receipent should receive just a 1 message, so in a summary: there are 3 messages to be sent.
Even that the connection is refused(just because there is not mail server on localhost) method send() returns 1 as a result... why?

Expected behaviour

It should allow to handle Connection refused error, or return this as a string message in $errors array.

Example

Because by default, SwiftMailer uses SpoolTransport, which implements Transport interface on its own, there is no place in StackTrace to handle an exception thrown by StreamBuffer then AbstractSmtpTransport, just because the AbstractSmtpTransport is not in the same trace as the SpoolTransport instance: one do not inherit after the second one.
Thus, I suggest to throw it higher so the users can handle it on their own or to pass the information in $errors array.

P.S: I guess I may be wrong, and please correct me if I am mistaken, thus if so, I am very sorry about wasting your time.

@0fca 0fca changed the title Don't know why or not being able to properly handle a case when the host is down. Don't know how to handle the case when connection is refused by a mail server. Mar 31, 2020
@cluster28
Copy link

Hi @Arkasian i'm looking for the same solution. There's no way to check if there's any problem with the server. I found that https://swiftmailer.symfony.com/docs/plugins.html#logger-plugin but I still don't know how to use it and if it's what we're looking for.

@0fca
Copy link
Author

0fca commented Apr 15, 2020

Sure, it can help sysops because it will log all problems with server from all around the SwiftMailer, but for us, I guess it has no real usage, as we want to avoid parsing logs to receive just as simple information as that the connection was refused or something. In my opinion they should just pass that information somehow higher in errors array or just leave the exception for user to be caught.

@cluster28
Copy link

I'm using Symfony so i could feedback the errors via Slack with swiftmailer-bundle

@0fca
Copy link
Author

0fca commented Apr 17, 2020

Tell me more about it, I don't know that, and I am using Symfony too. 3.4/4.4 with SwiftMailer.

@cluster28
Copy link

Hi @Arkasian:

Do you have this configuration in swiftmailer declaration?

spool: { type: memory }

If true the mails are sent at the end of the request so Symfony use this listener to send.

I had this configuration in my project but I removed it and I refactored the code to send mails directly when send method is called. This way if it fails an Exception is thrown and you can handler the error.

In my case i send this error to slack with monolog. I both cases you can send the error to slack.

Hope this helps you.

@0fca
Copy link
Author

0fca commented Apr 20, 2020

As far as I remember there is such configuration done in my project. I have to try it out. Thanks for a clue @cluster28 . I will get back to you if it will work for me too.

@fabpot fabpot closed this as completed Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants