powermail
powermail copied to clipboard
Flash message showing error is not submitted if sending of email fails (in case of exception)
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
- Use email configuration with smtp (most likely for this to work, we need synchronous sending of mail without mail queue)
- 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)
- create simple form with a field which is marked as sender email
- Now fill out form in FE and use a wrong email address
- Expected result: After sending the form, I would expect an error message.
- Actual result: no error message, only log message in error log (logging framework)
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 <[email protected]>... 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
(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
- TYPO3 12.4.18
- powermail (latest release): 12.3.5
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.