]> source.dussan.org Git - nextcloud-server.git/commitdiff
show if the mail server settings are not set or verified
authorszaimen <szaimen@e.mail.de>
Thu, 3 Feb 2022 10:43:17 +0000 (11:43 +0100)
committerszaimen <szaimen@e.mail.de>
Thu, 3 Feb 2022 19:16:35 +0000 (20:16 +0100)
Signed-off-by: szaimen <szaimen@e.mail.de>
apps/settings/lib/Controller/CheckSetupController.php
apps/settings/lib/Controller/MailSettingsController.php
apps/settings/templates/settings/admin/additional-mail.php
core/js/setupchecks.js

index ac734e5eb780f55cc771abdf897b5d8019c1dbbf..3a8b9bfd4a5d28394135c0a30eb9e7db2ac95504 100644 (file)
@@ -560,6 +560,20 @@ Raw output
                return \OC_Helper::isReadOnlyConfigEnabled();
        }
 
+       protected function wasEmailTestSuccessful(): bool {
+               // Handle the case that the configuration was set before the check was introduced or it was only set via command line and not from the UI
+               if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '' && $this->config->getSystemValue('mail_domain', '') === '') {
+                       return false;
+               }
+
+               // The mail test was unsuccessful or the config was changed using the UI without verifying with a testmail, hence return false
+               if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '0') {
+                       return false;
+               }
+
+               return true;
+       }
+
        protected function hasValidTransactionIsolationLevel(): bool {
                try {
                        if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
@@ -809,6 +823,7 @@ Raw output
                                'isGetenvServerWorking' => !empty(getenv('PATH')),
                                'isReadOnlyConfig' => $this->isReadOnlyConfig(),
                                'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
+                               'wasEmailTestSuccessful' => $this->wasEmailTestSuccessful(),
                                'hasFileinfoInstalled' => $this->hasFileinfoInstalled(),
                                'hasWorkingFileLocking' => $this->hasWorkingFileLocking(),
                                'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
index 04143cc7fa7d91402772ae014ecb6e427c606e76..22c0622a0722d4775c6cd4b3aa001776277ae303 100644 (file)
@@ -33,6 +33,7 @@ use OCP\AppFramework\Http\DataResponse;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IRequest;
+use OCP\IURLGenerator;
 use OCP\IUserSession;
 use OCP\Mail\IMailer;
 
@@ -46,6 +47,8 @@ class MailSettingsController extends Controller {
        private $userSession;
        /** @var IMailer */
        private $mailer;
+       /** @var IURLGenerator */
+       private $urlGenerator;
 
        /**
         * @param string $appName
@@ -53,6 +56,7 @@ class MailSettingsController extends Controller {
         * @param IL10N $l10n
         * @param IConfig $config
         * @param IUserSession $userSession
+        * @param IURLGenerator $urlGenerator,
         * @param IMailer $mailer
         */
        public function __construct($appName,
@@ -60,11 +64,13 @@ class MailSettingsController extends Controller {
                                                                IL10N $l10n,
                                                                IConfig $config,
                                                                IUserSession $userSession,
+                                                               IURLGenerator $urlGenerator,
                                                                IMailer $mailer) {
                parent::__construct($appName, $request);
                $this->l10n = $l10n;
                $this->config = $config;
                $this->userSession = $userSession;
+               $this->urlGenerator = $urlGenerator;
                $this->mailer = $mailer;
        }
 
@@ -107,6 +113,8 @@ class MailSettingsController extends Controller {
 
                $this->config->setSystemValues($configs);
 
+               $this->config->setAppValue('core', 'emailTestSuccessful', '0');
+
                return new DataResponse();
        }
 
@@ -130,6 +138,8 @@ class MailSettingsController extends Controller {
                        'mail_smtppassword' => $mail_smtppassword,
                ]);
 
+               $this->config->setAppValue('core', 'emailTestSuccessful', '0');
+
                return new DataResponse();
        }
 
@@ -159,14 +169,19 @@ class MailSettingsController extends Controller {
                                $message->useTemplate($template);
                                $errors = $this->mailer->send($message);
                                if (!empty($errors)) {
+                                       $this->config->setAppValue('core', 'emailTestSuccessful', '0');
                                        throw new \RuntimeException($this->l10n->t('Email could not be sent. Check your mail server log'));
                                }
+                               // Store the successful config in the app config
+                               $this->config->setAppValue('core', 'emailTestSuccessful', '1');
                                return new DataResponse();
                        } catch (\Exception $e) {
+                               $this->config->setAppValue('core', 'emailTestSuccessful', '0');
                                return new DataResponse($this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()]), Http::STATUS_BAD_REQUEST);
                        }
                }
 
-               return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails.'), Http::STATUS_BAD_REQUEST);
+               $this->config->setAppValue('core', 'emailTestSuccessful', '0');
+               return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails. Go to %s for that.', [$this->urlGenerator->linkToRouteAbsolute('settings.PersonalSettings.index')]), Http::STATUS_BAD_REQUEST);
        }
 }
index 82cd9e09b134b08d6ce65c3fd13e586e0f9693a2..a7e8382de183caa1e7e5ac1b36eee6ba68fcc996 100644 (file)
@@ -158,7 +158,7 @@ $mail_sendmailmode = [
        </form>
 
        <br />
-       <em><?php p($l->t('Test email settings')); ?></em>
+       <em><?php p($l->t('Test and verify email settings')); ?></em>
        <input type="submit" name="sendtestemail" id="sendtestemail" value="<?php p($l->t('Send email')); ?>"/>
        <span id="sendtestmail_msg" class="msg"></span>
 </div>
index 59411d67b99b104d46ee8e85fb2cd4cca3f991f2..94bf4d5403c6e0df685404fffb80e8318554b611 100644 (file)
                                                        type: OC.SetupChecks.MESSAGE_TYPE_INFO
                                                });
                                        }
+                                       if (!data.wasEmailTestSuccessful) {
+                                               messages.push({
+                                                       msg: t('core', 'You have not set or verified your email server configuration, yet. Please head over to the {mailSettingsStart} Basic settings {mailSettingsEnd} in order to set them. Afterwards, use the "Send email" button below the form to verify your settings.',)
+                                                       .replace('{mailSettingsStart} ', '<a href="' + OC.generateUrl('/settings/admin') + '">')
+                                                       .replace(' {mailSettingsEnd}', '</a>'),
+                                                       type: OC.SetupChecks.MESSAGE_TYPE_INFO
+                                               });
+                                       }
                                        if (!data.hasValidTransactionIsolationLevel) {
                                                messages.push({
                                                        msg: t('core', 'Your database does not run with "READ COMMITTED" transaction isolation level. This can cause problems when multiple actions are executed in parallel.'),