fixed email test
This commit is contained in:
parent
d8daf9f063
commit
2915a3bd35
|
@ -59,18 +59,10 @@ global $config;
|
|||
check_login();
|
||||
|
||||
if (is_ajax()) {
|
||||
enterprise_include_once('include/functions_cron.php');
|
||||
|
||||
$test_address = get_parameter('test_address', '');
|
||||
|
||||
$res = enterprise_hook(
|
||||
'send_email_attachment',
|
||||
[
|
||||
$test_address,
|
||||
__('This is an email test sent from Pandora FMS. If you can read this, your configuration works.'),
|
||||
__('Testing Pandora FMS email'),
|
||||
null,
|
||||
]
|
||||
$res = send_test_email(
|
||||
$test_address
|
||||
);
|
||||
|
||||
echo $res;
|
||||
|
@ -469,7 +461,6 @@ function show_email_test(id) {
|
|||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
height: 175,
|
||||
width: 450,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
|
@ -487,7 +478,11 @@ function perform_email_test () {
|
|||
data: "page=godmode/setup/setup_general&test_address="+test_address,
|
||||
dataType: "html",
|
||||
success: function(data) {
|
||||
if (parseInt(data) === 1) {
|
||||
$('#email_test_sent_message').show();
|
||||
} else {
|
||||
$('#email_test_failure_message').show();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#email_test_failure_message').show();
|
||||
|
|
|
@ -5735,3 +5735,60 @@ function get_data_multiplier($unit)
|
|||
|
||||
return $multiplier;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send test email to check email setups.
|
||||
*
|
||||
* @param string $to Target email account.
|
||||
*
|
||||
* @return integer Status of the email send task.
|
||||
*/
|
||||
function send_test_email(
|
||||
string $to
|
||||
) {
|
||||
global $config;
|
||||
|
||||
$result = false;
|
||||
try {
|
||||
$transport = new Swift_SmtpTransport(
|
||||
$config['email_smtpServer'],
|
||||
$config['email_smtpPort']
|
||||
);
|
||||
|
||||
$transport->setUsername($config['email_username']);
|
||||
$transport->setPassword($config['email_password']);
|
||||
|
||||
if ($config['email_encryption']) {
|
||||
$transport->setEncryption($config['email_encryption']);
|
||||
}
|
||||
|
||||
$mailer = new Swift_Mailer($transport);
|
||||
|
||||
$message = new Swift_Message(io_safe_output(__('Testing Pandora FMS email')));
|
||||
|
||||
$message->setFrom(
|
||||
[
|
||||
$config['email_from_dir'] => io_safe_output(
|
||||
$config['email_from_name']
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
$to = trim($to);
|
||||
$message->setTo([$to => $to]);
|
||||
$message->setBody(
|
||||
__('This is an email test sent from Pandora FMS. If you can read this, your configuration works.'),
|
||||
'text/html'
|
||||
);
|
||||
|
||||
ini_restore('sendmail_from');
|
||||
|
||||
$result = $mailer->send($message);
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
db_pandora_audit('Cron jobs mail', $e->getMessage());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue