diff --git a/typo3/sysext/install/Classes/Controller/EnvironmentController.php b/typo3/sysext/install/Classes/Controller/EnvironmentController.php
index 71d3e7db55e4184f79dd5624e47ac47dd2a9813f..05db0f086499a674dfb43ba39792b95c2c519a66 100644
--- a/typo3/sysext/install/Classes/Controller/EnvironmentController.php
+++ b/typo3/sysext/install/Classes/Controller/EnvironmentController.php
@@ -38,6 +38,7 @@ use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Install\FolderStructure\DefaultFactory;
 use TYPO3\CMS\Install\FolderStructure\DefaultPermissionsCheck;
+use TYPO3\CMS\Install\Service\LateBootService;
 use TYPO3\CMS\Install\SystemEnvironment\Check;
 use TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck;
 use TYPO3\CMS\Install\SystemEnvironment\SetupCheck;
@@ -48,6 +49,17 @@ use TYPO3\CMS\Install\SystemEnvironment\SetupCheck;
  */
 class EnvironmentController extends AbstractController
 {
+    /**
+     * @var LateBootService
+     */
+    private $lateBootService;
+
+    public function __construct(
+        LateBootService $lateBootService
+    ) {
+        $this->lateBootService = $lateBootService;
+    }
+
     /**
      * Main "show the cards" view
      *
@@ -239,6 +251,8 @@ class EnvironmentController extends AbstractController
      */
     public function mailTestAction(ServerRequestInterface $request): ResponseInterface
     {
+        $container = $this->lateBootService->getContainer();
+        $backup = $this->lateBootService->makeCurrent($container);
         $messages = new FlashMessageQueue('install');
         $recipient = $request->getParsedBody()['install']['email'];
         if (empty($recipient) || !GeneralUtility::validEmail($recipient)) {
@@ -283,6 +297,7 @@ class EnvironmentController extends AbstractController
                 ));
             }
         }
+        $this->lateBootService->makeCurrent(null, $backup);
         return new JsonResponse([
             'success' => true,
             'status' => $messages,
diff --git a/typo3/sysext/install/Classes/ServiceProvider.php b/typo3/sysext/install/Classes/ServiceProvider.php
index ce153a61e94645ad2c7df971a1a5006715142227..e7279fa076b4ab0012818328f055659f17fadcde 100644
--- a/typo3/sysext/install/Classes/ServiceProvider.php
+++ b/typo3/sysext/install/Classes/ServiceProvider.php
@@ -47,6 +47,7 @@ class ServiceProvider extends AbstractServiceProvider
             Service\ClearCacheService::class => [ static::class, 'getClearCacheService' ],
             Service\LoadTcaService::class => [ static::class, 'getLoadTcaService' ],
             Middleware\Maintenance::class => [ static::class, 'getMaintenanceMiddleware' ],
+            Controller\EnvironmentController::class => [ static::class, 'getEnvironmentController' ],
             Controller\UpgradeController::class => [ static::class, 'getUpgradeController' ],
             Command\LanguagePackCommand::class => [ static::class, 'getLanguagePackCommand' ],
             Command\UpgradeWizardRunCommand::class => [ static::class, 'getUpgradeWizardRunCommand' ],
@@ -107,6 +108,13 @@ class ServiceProvider extends AbstractServiceProvider
         );
     }
 
+    public static function getEnvironmentController(ContainerInterface $container): Controller\EnvironmentController
+    {
+        return new Controller\EnvironmentController(
+            $container->get(Service\LateBootService::class)
+        );
+    }
+
     public static function getUpgradeController(ContainerInterface $container): Controller\UpgradeController
     {
         return new Controller\UpgradeController(