From 5b8cde48dc6d68a3921195b5367024b94abe14af Mon Sep 17 00:00:00 2001
From: Joas Schilling
Date: Wed, 26 Feb 2014 12:13:20 +0100
Subject: Add button to send a test mail after changing the email settings
Fix #7175
---
settings/admin/controller.php | 30 ++++++++++++++++++++++++++++++
settings/js/admin.js | 12 ++++++++++--
settings/routes.php | 3 +++
settings/templates/admin.php | 6 +++++-
4 files changed, 48 insertions(+), 3 deletions(-)
(limited to 'settings')
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
@@ -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
*
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']) {
+
+ t( 'Test email settings' )); ?>
+
+