]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add button to send a test mail after changing the email settings
authorJoas Schilling <nickvergessen@gmx.de>
Wed, 26 Feb 2014 11:13:20 +0000 (12:13 +0100)
committerJoas Schilling <nickvergessen@gmx.de>
Wed, 5 Mar 2014 09:01:34 +0000 (10:01 +0100)
Fix #7175

settings/admin/controller.php
settings/js/admin.js
settings/routes.php
settings/templates/admin.php

index a075d7743616c1df2e08ed1993b63f9a468f280b..7019f9a4d2ae0806a4ee7e77a850170305154c94 100644 (file)
@@ -73,6 +73,36 @@ class Controller {
                \OC_JSON::success(array("data" => array( "message" => $l->t("Saved") )));
        }
 
+       /**
+        * Send a mail to test the settings
+        */
+       public static function sendTestMail() {
+               \OC_Util::checkAdminUser();
+               \OCP\JSON::callCheck();
+
+               $l = \OC_L10N::get('settings');
+               $email = \OC_Preferences::getValue(\OC_User::getUser(), 'settings', 'email', '');
+               if (!empty($email)) {
+                       $defaults = new \OC_Defaults();
+
+                       try {
+                               \OC_Mail::send($email, $_POST['user'],
+                                       $l->t('test email settings'),
+                                       $l->t('If you received this email, the settings seem to be correct.'),
+                                       \OCP\Util::getDefaultEmailAddress('no-reply'), $defaults->getName());
+                       } catch (\Exception $e) {
+                               $message = $l->t('A problem occurred while sending the e-mail. Please revisit your settings.');
+                               \OC_JSON::error( array( "data" => array( "message" => $message)) );
+                               exit;
+                       }
+
+                       \OC_JSON::success(array("data" => array( "message" => $l->t("Email sent") )));
+               } else {
+                       $message = $l->t('You need to set your user email before being able to send test emails.');
+                       \OC_JSON::error( array( "data" => array( "message" => $message)) );
+               }
+       }
+
        /**
         * Get the field name to use it in error messages
         *
index 5ea6a5af2df2db8980c7039bab6a3dbbb2a7b1c8..684822f18342aa892b18cab448ca0f544c592619 100644 (file)
@@ -62,10 +62,18 @@ $(document).ready(function(){
        });
 
        $('#mail_settings').change(function(){
-               OC.msg.startSaving('#mail_settings .msg');
+               OC.msg.startSaving('#mail_settings_msg');
                var post = $( "#mail_settings" ).serialize();
                $.post(OC.Router.generate('settings_mail_settings'), post, function(data){
-                       OC.msg.finishedSaving('#mail_settings .msg', data);
+                       OC.msg.finishedSaving('#mail_settings_msg', data);
+               });
+       });
+
+       $('#sendtestemail').click(function(){
+               OC.msg.startAction('#sendtestmail_msg', t('settings', 'Sending...'));
+               var post = $( "#sendtestemail" ).serialize();
+               $.post(OC.Router.generate('settings_admin_mail_test'), post, function(data){
+                       OC.msg.finishedAction('#sendtestmail_msg', data);
                });
        });
 });
index 64f7122f0cf6492cbe0365e386f574df80ff4279..a0d54dea1e7df581a49508fe974800f9cf2bc4f7 100644 (file)
@@ -73,5 +73,8 @@ $this->create('settings_ajax_setloglevel', '/settings/ajax/setloglevel.php')
 $this->create('settings_mail_settings', '/settings/admin/mailsettings')
        ->post()
        ->action('OC\Settings\Admin\Controller', 'setMailSettings');
+$this->create('settings_admin_mail_test', '/settings/admin/mailtest')
+       ->post()
+       ->action('OC\Settings\Admin\Controller', 'sendTestMail');
 $this->create('settings_ajax_setsecurity', '/settings/ajax/setsecurity.php')
        ->actionInclude('settings/ajax/setsecurity.php');
index 139a9dd076c11816992d1444575b4b8f0701e2fb..487da036e74c5dde4780b49d8d31c7e474fe0675 100644 (file)
@@ -272,7 +272,7 @@ if (!$_['internetconnectionworking']) {
 </fieldset>
 
 <fieldset id="mail_settings" class="personalblock">
-       <h2><?php p($l->t('Email Server'));?> <span class="msg"></span></h2>
+       <h2><?php p($l->t('Email Server'));?> <span id="mail_settings_msg" class="msg"></span></h2>
 
        <p><?php p($l->t('This is used for sending out notifications.')); ?></p>
 
@@ -347,6 +347,10 @@ if (!$_['internetconnectionworking']) {
                           placeholder="<?php p($l->t('SMTP Password'))?>" value='<?php p($_['mail_smtppassword']) ?>' />
        </p>
 
+       <br />
+       <em><?php p($l->t( 'Test email settings' )); ?></em>
+       <input type="submit" name="sendtestemail" id="sendtestemail" value="<?php p($l->t( 'Send email' )); ?>"/>
+       <span id="sendtestmail_msg" class="msg"></span>
 </fieldset>
 
 <fieldset class="personalblock">