]> 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)
committerSimon L. (Rebase PR Action) <szaimen@e.mail.de>
Tue, 15 Feb 2022 22:56:47 +0000 (22:56 +0000)
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 3c7d5a5c0aba0e9a86d16c3a1b903bddf44fdcdc..11900fad45b9e2b8b50ca840427099376944966c 100644 (file)
@@ -572,6 +572,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) {
@@ -822,6 +836,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 8e6f17f07ede95f0a3e68983870f024a29858a96..5976f3b701c10326194695cba050c1bae24f81ad 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.'),