mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-23 03:32:32 -08:00
Fixes #4036 - adds test email button to general settings
This commit is contained in:
parent
cb50142ba3
commit
cd193ce8bb
|
@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Models\Ldap;
|
||||
use Validator;
|
||||
use App\Models\Setting;
|
||||
use Mail;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
|
@ -160,4 +161,28 @@ class SettingsController extends Controller
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the email configuration
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @return Redirect
|
||||
*/
|
||||
public function ajaxTestEmail()
|
||||
{
|
||||
try {
|
||||
Mail::send('emails.test', [], function ($m) {
|
||||
$m->to(config('mail.from.address'), config('mail.from.name'));
|
||||
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
|
||||
$m->subject(trans('mail.test_email'));
|
||||
});
|
||||
return response()->json(['message' => 'Mail sent! '], 200);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use App\Models\User;
|
|||
use App\Http\Requests\SetupUserRequest;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use App\Http\Requests\SettingsLdapRequest;
|
||||
use App\Helpers\Helper;
|
||||
|
||||
/**
|
||||
* This controller handles all actions related to Settings for
|
||||
|
@ -1020,9 +1021,9 @@ class SettingsController extends Controller
|
|||
$m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name'));
|
||||
$m->subject(trans('mail.test_email'));
|
||||
});
|
||||
return response()->json(['message' => 'Mail sent! '], 200);
|
||||
return response()->json(Helper::formatStandardApiResponse('success', null, 'Maiol sent!'));
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 500);
|
||||
return response()->json(Helper::formatStandardApiResponse('success', null, $e->getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@
|
|||
<div id="mailteststatus-error" class="text-danger"></div>
|
||||
</div>
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<p class="help-block">This will attempt to send a test mail to {{ config('mail.reply_to.address') }}.</p>
|
||||
<p class="help-block">This will attempt to send a test mail to {{ config('mail.from.address') }}.</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -235,10 +235,12 @@
|
|||
$("#mailtest").click(function(){
|
||||
$("#mailtestrow").removeClass('text-success');
|
||||
$("#mailtestrow").removeClass('text-danger');
|
||||
$("#mailtesticon").html('');
|
||||
$("#mailteststatus").html('');
|
||||
$('#mailteststatus-error').html('');
|
||||
$("#mailtesticon").html('<i class="fa fa-spinner spin"></i> Sending Test Email...');
|
||||
$.ajax({
|
||||
url: '{{ route('settings.mailtest') }}',
|
||||
url: '{{ route('api.settings.mailtest') }}',
|
||||
type: 'POST',
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
|
@ -265,7 +267,11 @@
|
|||
$("#mailteststatus").addClass('text-danger');
|
||||
$("#mailtesticon").html('<i class="fa fa-exclamation-triangle text-danger"></i>');
|
||||
$('#mailteststatus').html('Mail could not be sent.');
|
||||
$('#mailteststatus-error').html('Error: ' + data.responseJSON.messages);
|
||||
if (data.responseJSON) {
|
||||
$('#mailteststatus-error').html('Error: ' + data.responseJSON.messages);
|
||||
} else {
|
||||
console.dir(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -165,13 +165,22 @@ Create a User ::
|
|||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id="mailrow">
|
||||
<tr id="mailtestrow" class="warning">
|
||||
<td>Email</td>
|
||||
<td id="mailtesticon">
|
||||
<td>
|
||||
<a class="btn btn-default btn-sm pull-left" id="mailtest" style="margin-right: 10px;">
|
||||
Send Test</a>
|
||||
</td>
|
||||
<td id="mailtestresult">
|
||||
<button class="btn btn-default" id="mailtest"> Test Email</button>
|
||||
<span id="mailtestresult"></span>
|
||||
<td>
|
||||
<span id="mailtesticon"></span>
|
||||
<span id="mailtestresult"></span>
|
||||
<span id="mailteststatus"></span>
|
||||
<div class="col-md-12">
|
||||
<div id="mailteststatus-error" class="text-danger"></div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<p class="help-block">This will attempt to send a test mail to {{ config('mail.from.address') }}.</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -190,34 +199,61 @@ Create a User ::
|
|||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
|
||||
$("#mailtest").click(function(){
|
||||
// Test Mail
|
||||
|
||||
$("#mailtestresult").html('<i class="fa fa-spinner fa-spin"></i> Sending Email');
|
||||
$("#mailtest").click(function(){
|
||||
|
||||
$.ajax({url: "{{ route('setup.mailtest') }}", success: function(result){
|
||||
if (result=='success') {
|
||||
$("#mailrow").addClass('success');
|
||||
$("#mailtesticon").html('<i class="fa fa-check preflight-success"></i>');
|
||||
$("#mailtestresult").html('No errors on this end! Check your <code>{{ config('mail.from.address') }}</code> email account for a test email.');
|
||||
} else {
|
||||
$("#mailrow").addClass('danger');
|
||||
$("#mailtesticon").html('<i class="fa fa-check preflight-error"></i>');
|
||||
$("#mailtestresult").html('Something went wrong. Your email was not sent. Check your mail settings in your <code>.env</code> file.');
|
||||
$("#mailtestrow").removeClass('success').removeClass('danger').removeClass('warning');
|
||||
$("#mailtestrow").addClass('info');
|
||||
$("#mailtesticon").html('');
|
||||
$("#mailteststatus").html('');
|
||||
$('#mailteststatus-error').html('');
|
||||
$("#mailtesticon").html('<i class="fa fa-spinner spin"></i> Sending Test Email...');
|
||||
|
||||
}
|
||||
$.ajax({
|
||||
url: "{{ route('setup.mailtest') }}",
|
||||
|
||||
success: function (result) {
|
||||
if (result.status == 'success') {
|
||||
$("#mailtestrow").removeClass('info').removeClass('danger').removeClass('warning');
|
||||
$("#mailtestrow").addClass('success');
|
||||
$("#mailtesticon").html('');
|
||||
$("#mailteststatus").html('');
|
||||
$('#mailteststatus-error').html('');
|
||||
$("#mailteststatus").removeClass('text-danger');
|
||||
$("#mailteststatus").addClass('text-success');
|
||||
$("#mailteststatus").html('<i class="fa fa-check text-success"></i> Mail sent to {{ config('mail.from.address') }}!');
|
||||
} else {
|
||||
$("#mailtestrow").removeClass('success').removeClass('info').removeClass('warning');
|
||||
$("#mailtestrow").addClass('danger');
|
||||
$("#mailtesticon").html('<i class="fa fa-check preflight-error"></i>');
|
||||
$("#mailtestresult").html('Something went wrong. Your email was not sent. Check your mail settings in your <code>.env</code> file.');
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
error: function (result) {
|
||||
$("#mailrow").addClass('danger');
|
||||
$("#mailtesticon").html('<i class="fa fa-check preflight-error"></i>');
|
||||
$("#mailtestresult").html('Something went wrong. The server returned an error. Check your mail settings in your <code>.env</code> file, and check your <code>storage/logs</code> for additional information..');
|
||||
}
|
||||
},
|
||||
error: function (result) {
|
||||
$("#mailtestrow").removeClass('success').removeClass('info').removeClass('warning');
|
||||
$("#mailtestrow").addClass('danger');
|
||||
$("#mailtesticon").html('');
|
||||
$("#mailteststatus").html('');
|
||||
$('#mailteststatus-error').html('');
|
||||
$("#mailteststatus").removeClass('text-success');
|
||||
$("#mailteststatus").addClass('text-danger');
|
||||
$("#mailtesticon").html('<i class="fa fa-exclamation-triangle text-danger"></i>');
|
||||
$('#mailteststatus').html('Mail could not be sent.');
|
||||
if (result.responseJSON) {
|
||||
$('#mailteststatus-error').html('Error: ' + result.responseJSON.messages);
|
||||
} else {
|
||||
console.dir(data);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@stop
|
||||
|
|
|
@ -428,7 +428,15 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
'as' => 'api.settings.ldaptestlogin',
|
||||
'uses' => 'SettingsController@ldaptestlogin'
|
||||
]);
|
||||
|
||||
|
||||
Route::post(
|
||||
'settings/mailtest',
|
||||
[
|
||||
'as' => 'api.settings.mailtest',
|
||||
'uses' => 'SettingsController@ajaxTestEmail' ]
|
||||
);
|
||||
|
||||
|
||||
Route::resource('settings', 'SettingsController',
|
||||
[
|
||||
'names' =>
|
||||
|
|
Loading…
Reference in a new issue