Project

General

Profile

Actions

Bug #96788

closed

"Test Mail Setup" cannot send mails if HTML mail template uses <f:format.html>

Added by Felix Heller about 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2022-02-08
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
11
PHP Version:
8.0
Tags:
Complexity:
medium
Is Regression:
Yes
Sprint Focus:

Description

In TYPO3 11.5.6, it's not possible to send a mail in the "Test Mail Setup" (backend module "Environment" or install tool) if the mail HTML template uses the Fluid ViewHelper f:format.html. The following error occurs:

Could not deliver mail
Please verify $GLOBALS['TYPO3_CONF_VARS']['MAIL'][*] settings are valid. Error message: No valid attribute "applicationType" found in request object.

This worked well in TYPO3 10.4. Without the usage of the Fluid HTML ViewHelper or with the default mail template, the test mail is sent correctly in TYPO3 11.5, too.

Steps to reproduce the error:

  • In the LocalConfiguration.php, add an additional template root path:
    'MAIL' => [
        // ... other configuration options ...
        'templateRootPaths' => [
            20 => 'EXT:example/Resources/Private/Templates/Email/',
        ],
  • Create a HTML template file EXT:example/Resources/Private/Templates/Email/Default.html:
    <f:layout name="SystemEmail" />
    <f:section name="Main">
        {content -> f:format.html()}
    </f:section>
  • Try to send a test mail in the install tool or the TYPO3 backend by using the "Test Mail Setup".

The error is thrown in the class \TYPO3\CMS\Core\Http\ApplicationType in the method fromRequest(ServerRequestInterface $request).
It is called in \TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlViewHelper:

public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
    $parseFuncTSPath = $arguments['parseFuncTSPath'];
    $isBackendRequest = ApplicationType::fromRequest($renderingContext->getRequest())->isBackend();

The request of the Fluid rendering context doesn't have an application type attribute set.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Task #94497: Avoid access of global request in view helpers ClosedOliver Bartsch2021-07-06

Actions
Actions #1

Updated by Felix Heller about 2 years ago

  • Related to Task #94497: Avoid access of global request in view helpers added
Actions #2

Updated by Felix Heller about 2 years ago

  • Category changed from Mailer API to Fluid
  • Is Regression set to Yes

The commit c5290640 changed the way how the TYPO3 request is handled in the Fluid HtmlViewHelper. Before it was:

$isBackendRequest = ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
    && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend();

Now it's:

$isBackendRequest = ApplicationType::fromRequest($renderingContext->getRequest())->isBackend();

I've reverted this change in my local TYPO3 installation and now it's working again to send a test mail in the install tool when I'm using a HtmlViewHelper in my individual mail layout.

I also found out that the same bug occurs if I'm trying to send a FluidEmail in a Symfony console command.

Actions #3

Updated by Gerrit Code Review about 2 years ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73422

Actions #4

Updated by Gerrit Code Review about 2 years ago

Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73423

Actions #5

Updated by Christian Kuhn about 2 years ago

Had a chat with Oli on this. There are multiple points here.

  • The fact that the install tool 'test mail setup' obeys configured templates overrides is imho unfortunate. The goal of that card is to test if the low-level mail setup works (php can submit a mail to some endpoint). It should (imho) NOT be used to test if mail overrides are working as expected - this can and shoud only be done using the specific application part that sends a mail.
  • Class FluidEmail has a dependency to Request! This is only shadowed away since StandaloneView creates a request on-the-fly, which is a hack & violation and needs to be avoided. FluidEmail thus needs a solution to get the current request, should enforce that (maybe with a fallback layer in v12 to globals['typo3_request'] that is removed in v13) an should set that request to the view.
  • When FluidEmail makes it dependency to Request explicit, CLI commands that send an email will crash. That is exactly what we want for CLI: If your command has a dependency to Request, and if CLI does not provide a Request, that command should crash. Those commands then need to create a 'fake' request, which for instance then knows if it is a backend or frontend application related request. Making this explicit is much better than trying to deal with 'no-request-available-so-i-create-something' at arbitrary places in the system (like in StandaloneView): Only the specific command knows details which Request should be created when it calls frontend or backend related stuff like rendering a frontend page or rendering an email that has a dependency to request due to viewhelpers that needs requests.

The above points should all be solved in v12.

For v11: We can mitigate the issue in HtmlViewHelper, so it does not crash anymore, and that is the solution to go with for now.

Note the same scenario then still crashes in v12 already again, since ContentObjectRenderer parsefunc (used by f:format.html) logs a deprecation in v11 for invalid configuration and explodes in v12. This would be gone in install tool if we decide to drop the 'obey template override' mechanic in 'send test mail'.

Actions #6

Updated by Gerrit Code Review about 2 years ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73422

Actions #7

Updated by Gerrit Code Review about 2 years ago

Patch set 2 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73423

Actions #8

Updated by Oliver Bartsch about 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #9

Updated by Gerrit Code Review about 2 years ago

  • Status changed from Resolved to Under Review

Patch set 3 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73423

Actions #10

Updated by Oliver Bartsch about 2 years ago

  • Status changed from Under Review to Resolved
Actions #11

Updated by Benni Mack over 1 year ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF