[BUGFIX] Provide error messages in install tool mail settings test 02/61802/2
authorOliver Hader <oliver@typo3.org>
Tue, 24 Sep 2019 17:55:29 +0000 (19:55 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 25 Sep 2019 10:34:26 +0000 (12:34 +0200)
In order to identify problems with sending out mails, more specific
error messages than "Something went wrong" are used.

Resolves: #89254
Releases: master, 9.5
Change-Id: I61d8b122f7af764cfd5be0b08b27c99cd4fd56e0
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61802
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Build/Sources/TypeScript/install/Resources/Public/TypeScript/Module/Environment/MailTest.ts
typo3/sysext/install/Classes/Controller/EnvironmentController.php
typo3/sysext/install/Resources/Public/JavaScript/Module/Environment/MailTest.js

index deb3bfd..17b2071 100644 (file)
@@ -74,7 +74,7 @@ class MailTest extends AbstractInteractableModule {
       cache: false,
       success: (data: any): void => {
         $outputContainer.empty();
-        if (data.success === true && Array.isArray(data.status)) {
+        if (Array.isArray(data.status)) {
           data.status.forEach((element: any): void => {
             const aMessage: any = InfoBox.render(element.severity, element.title, element.message);
             $outputContainer.html(aMessage);
index 27481f5..eac575b 100644 (file)
@@ -235,6 +235,7 @@ class EnvironmentController extends AbstractController
     {
         $messages = new FlashMessageQueue('install');
         $recipient = $request->getParsedBody()['install']['email'];
+        $delivered = false;
         if (empty($recipient) || !GeneralUtility::validEmail($recipient)) {
             $messages->enqueue(new FlashMessage(
                 'Given address is not a valid email address.',
@@ -242,18 +243,35 @@ class EnvironmentController extends AbstractController
                 FlashMessage::ERROR
             ));
         } else {
-            $mailMessage = GeneralUtility::makeInstance(MailMessage::class);
-            $mailMessage
-                ->to($recipient)
-                ->from(new NamedAddress($this->getSenderEmailAddress(), $this->getSenderEmailName()))
-                ->subject($this->getEmailSubject())
-                ->html('<html><body>html test content</body></html>')
-                ->text('plain test content')
-                ->send();
-            $messages->enqueue(new FlashMessage(
-                'Recipient: ' . $recipient,
-                'Test mail sent'
-            ));
+            try {
+                $mailMessage = GeneralUtility::makeInstance(MailMessage::class);
+                $mailMessage
+                    ->to($recipient)
+                    ->from(new NamedAddress($this->getSenderEmailAddress(), $this->getSenderEmailName()))
+                    ->subject($this->getEmailSubject())
+                    ->html('<html><body>html test content</body></html>')
+                    ->text('plain test content')
+                    ->send();
+                $messages->enqueue(new FlashMessage(
+                    'Recipient: ' . $recipient,
+                    'Test mail sent'
+                ));
+                $delivered = true;
+            } catch (\Symfony\Component\Mime\Exception\RfcComplianceException $exception) {
+                $messages->enqueue(new FlashMessage(
+                    'Please verify $GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][\'defaultMailFromAddress\'] is a valid mail address.'
+                    . ' Error message: ' . $exception->getMessage(),
+                    'RFC compliance problem',
+                    FlashMessage::ERROR
+                ));
+            } catch (\Throwable $throwable) {
+                $messages->enqueue(new FlashMessage(
+                    'Please verify $GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'][*] settings are valid.'
+                    . ' Error message: ' . $throwable->getMessage(),
+                    'Could not deliver mail',
+                    FlashMessage::ERROR
+                ));
+            }
         }
         return new JsonResponse([
             'success' => true,
index dd94510..b4e6a9a 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","../AbstractInteractableModule","jquery","../../Router","../../Renderable/ProgressBar","../../Renderable/Severity","../../Renderable/InfoBox","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Notification","bootstrap"],function(t,e,s,r,a,n,o,i,l,c){"use strict";return new class extends s.AbstractInteractableModule{constructor(){super(...arguments),this.selectorOutputContainer=".t3js-mailTest-output",this.selectorMailTestButton=".t3js-mailTest-execute"}initialize(t){this.currentModal=t,this.getData(),t.on("click",this.selectorMailTestButton,t=>{t.preventDefault(),this.send()})}getData(){const t=this.getModalBody();r.ajax({url:a.getUrl("mailTestGetData"),cache:!1,success:e=>{!0===e.success?(t.empty().append(e.html),l.setButtons(e.buttons)):c.error("Something went wrong")},error:e=>{a.handleAjaxError(e,t)}})}send(){const t=this.getModuleContent().data("mail-test-token"),e=this.findInModal(this.selectorOutputContainer),s=n.render(o.loading,"Loading...","");e.empty().html(s),r.ajax({url:a.getUrl(),method:"POST",data:{install:{action:"mailTest",token:t,email:this.findInModal(".t3js-mailTest-email").val()}},cache:!1,success:t=>{e.empty(),!0===t.success&&Array.isArray(t.status)?t.status.forEach(t=>{const s=i.render(t.severity,t.title,t.message);e.html(s)}):c.error("Something went wrong")},error:()=>{c.error("Something went wrong")}})}}});
\ No newline at end of file
+define(["require","exports","../AbstractInteractableModule","jquery","../../Router","../../Renderable/ProgressBar","../../Renderable/Severity","../../Renderable/InfoBox","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Notification","bootstrap"],function(t,e,r,s,a,n,o,i,l,c){"use strict";return new class extends r.AbstractInteractableModule{constructor(){super(...arguments),this.selectorOutputContainer=".t3js-mailTest-output",this.selectorMailTestButton=".t3js-mailTest-execute"}initialize(t){this.currentModal=t,this.getData(),t.on("click",this.selectorMailTestButton,t=>{t.preventDefault(),this.send()})}getData(){const t=this.getModalBody();s.ajax({url:a.getUrl("mailTestGetData"),cache:!1,success:e=>{!0===e.success?(t.empty().append(e.html),l.setButtons(e.buttons)):c.error("Something went wrong")},error:e=>{a.handleAjaxError(e,t)}})}send(){const t=this.getModuleContent().data("mail-test-token"),e=this.findInModal(this.selectorOutputContainer),r=n.render(o.loading,"Loading...","");e.empty().html(r),s.ajax({url:a.getUrl(),method:"POST",data:{install:{action:"mailTest",token:t,email:this.findInModal(".t3js-mailTest-email").val()}},cache:!1,success:t=>{e.empty(),Array.isArray(t.status)?t.status.forEach(t=>{const r=i.render(t.severity,t.title,t.message);e.html(r)}):c.error("Something went wrong")},error:()=>{c.error("Something went wrong")}})}}});
\ No newline at end of file