in2code-de / powermail

This is the official repository of the TYPO3 extension powermail! Powermail is a well-known, editor-friendly, powerful and easy mailform extension for TYPO3
https://in2code.de
86 stars 174 forks source link

Flash message showing error is not submitted if sending of email fails (in case of exception) #1100

Open sypets opened 1 month ago

sypets commented 1 month ago

This is related to https://github.com/in2code-de/powermail/issues/1087, but not the same issue. In fact, to solve https://github.com/in2code-de/powermail/issues/1087 I am using a patched version.

Reproduce

  1. Use email configuration with smtp (most likely for this to work, we need synchronous sending of mail without mail queue)
  2. make sure flash messages are displayed properly, e.g .with fix https://github.com/in2code-de/powermail/pull/1092 (or just debug to make sure flash messages are not submitted)
  3. create simple form with a field which is marked as sender email

image

  1. Now fill out form in FE and use a wrong email address

image

I do have a log message, so I know an exception is thrown:

Tue, 13 Aug 2024 15:31:18 +0200 [CRITICAL] request="97db7bed8235d" component="In2code.Powermail.Controller.FormController": Mail could not be sent - {"0":"Expected response code \"250/251/252\" but got code \"550\", with message \"550 5.1.1 <fehlerhafte-email@whatever-this-is-wrong.de>... User unknown\".","url":"https://mysite.de/test/powermail/powermail-einfaches-formular_intranet?tx_powermail_pi1%5Baction%5D=checkCreate&tx_powermail_pi1%5Bcontroller%5D=Form&cHash=ff72d9da8605e047124607eb4cc8e6c1"}

Possible fix

Fix in FormController:sendMailPreflight

         } catch (Throwable $exception) {
             $logger = ObjectUtility::getLogger(__CLASS__);
             $logger->critical('Mail could not be sent', [$exception->getMessage()]);
+            $this->addFlashMessage(
+                LocalizationUtility::translate('error_mail_not_created'),
+                '',
+                \TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::ERROR
+            );
+            $this->messageClass = 'error';
         }

https://github.com/in2code-de/powermail/blob/master/Classes/Controller/FormController.php#L394

image

(ideally a more specific message would be displayed - we know email sending failed and we could even differentiate between mail to sender and mail to receiver.)

Versions

sypets commented 1 month ago

Additionally: Ideally a more specific message would be displayed - we know email sending failed and we could even differentiate between mail to sender and mail to receiver.