diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-02-26 12:13:20 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-03-05 10:01:34 +0100 |
commit | 5b8cde48dc6d68a3921195b5367024b94abe14af (patch) | |
tree | 0675ce506a9f32ddda610afaf76d623c6dde5ce8 /settings/admin | |
parent | 2f0db9af07013655393ba199a1890fbf0e55ba0f (diff) | |
download | nextcloud-server-5b8cde48dc6d68a3921195b5367024b94abe14af.tar.gz nextcloud-server-5b8cde48dc6d68a3921195b5367024b94abe14af.zip |
Add button to send a test mail after changing the email settings
Fix #7175
Diffstat (limited to 'settings/admin')
-rw-r--r-- | settings/admin/controller.php | 30 |
1 files changed, 30 insertions, 0 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 |