2017-06-10 09:17:54 +02:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @api {post} /system/test-smtp Test SMTP Connection
|
2020-01-25 01:37:05 +01:00
|
|
|
* @apiVersion 4.6.0
|
2017-06-10 09:17:54 +02:00
|
|
|
*
|
|
|
|
* @apiName Test SMTP Connection
|
|
|
|
*
|
|
|
|
* @apiGroup System
|
|
|
|
*
|
|
|
|
* @apiDescription Test if the given values connect correctly to a SMTP server.
|
|
|
|
*
|
|
|
|
* @apiPermission any
|
|
|
|
*
|
|
|
|
* @apiParam {String} smtp-host Host of the SMTP server.
|
|
|
|
* @apiParam {String} smtp-port Port of the SMTP server.
|
|
|
|
* @apiParam {String} smtp-user User for the SMTP server.
|
|
|
|
* @apiParam {String} smtp-pass Password for the SMTP server.
|
|
|
|
*
|
|
|
|
* @apiUse SMTP_CONNECTION
|
|
|
|
*
|
|
|
|
* @apiSuccess {Object} data Empty object
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class TestSMTPController extends Controller {
|
|
|
|
const PATH = '/test-smtp';
|
|
|
|
const METHOD = 'POST';
|
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'any',
|
|
|
|
'requestData' => []
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
$mailSender = MailSender::getInstance();
|
|
|
|
$mailSender->setConnectionSettings(
|
|
|
|
Controller::request('smtp-host'),
|
|
|
|
Controller::request('smtp-user'),
|
2018-12-24 01:44:59 +01:00
|
|
|
Controller::request('smtp-pass'),
|
|
|
|
''
|
2017-06-10 09:17:54 +02:00
|
|
|
);
|
2018-06-04 23:04:03 +02:00
|
|
|
|
2017-06-10 09:17:54 +02:00
|
|
|
if($mailSender->isConnected()) {
|
|
|
|
Response::respondSuccess();
|
|
|
|
} else {
|
2018-11-20 23:41:00 +01:00
|
|
|
throw new RequestException(ERRORS::SMTP_CONNECTION);
|
2017-06-10 09:17:54 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-04 23:04:03 +02:00
|
|
|
}
|