summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-03-05 13:18:41 +0100
committerJoas Schilling <nickvergessen@gmx.de>2014-03-05 13:18:41 +0100
commitd583d61b6996b54c26326e5fa952bb4c2f4aa499 (patch)
treeabf5737cca599b56000107e92fd096e7cdd6cf07
parent2cfd875e616fa0770441a17d6f96a9f5f45e8c3f (diff)
parent5b8cde48dc6d68a3921195b5367024b94abe14af (diff)
downloadnextcloud-server-d583d61b6996b54c26326e5fa952bb4c2f4aa499.tar.gz
nextcloud-server-d583d61b6996b54c26326e5fa952bb4c2f4aa499.zip
Merge pull request #7412 from owncloud/issue/7175
Add button to send a test mail after changing the email settings
-rw-r--r--settings/admin/controller.php30
-rw-r--r--settings/js/admin.js12
-rw-r--r--settings/routes.php3
-rw-r--r--settings/templates/admin.php6
4 files changed, 48 insertions, 3 deletions
diff --git a/settings/admin/controller.php b/settings/admin/controller.php
index a075d774361..7019f9a4d2a 100644
--- a/settings/admin/controller.php
+++ b/settings/admin/controller.php
@@ -74,6 +74,36 @@ class Controller {
}
/**
+ * 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
*
* @param $setting string
diff --git a/settings/js/admin.js b/settings/js/admin.js
index 5ea6a5af2df..684822f1834 100644
--- a/settings/js/admin.js
+++ b/settings/js/admin.js
@@ -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);
});
});
});
diff --git a/settings/routes.php b/settings/routes.php
index 64f7122f0cf..a0d54dea1e7 100644
--- a/settings/routes.php
+++ b/settings/routes.php
@@ -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');
diff --git a/settings/templates/admin.php b/settings/templates/admin.php
index 139a9dd076c..487da036e74 100644
--- a/settings/templates/admin.php
+++ b/settings/templates/admin.php
@@ -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">