Merge pull request #7412 from owncloud/issue/7175

Add button to send a test mail after changing the email settings
This commit is contained in:
Joas Schilling 2014-03-05 13:18:41 +01:00
commit d583d61b69
4 changed files with 48 additions and 3 deletions

View 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
*

View 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);
});
});
});

View 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');

View 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">