From 826919579556f6ea5170a687a59ff4e61e600d3b Mon Sep 17 00:00:00 2001 From: Mark Oudsen Date: Mon, 10 Jul 2023 11:21:48 +0200 Subject: [PATCH] v2.14 - Adding ability to set 'From' address details in configuration --- README.md | 2 +- config/config.json.template | 2 -- config/config.json.template.multigraph | 5 ++--- mailGraph.php | 25 ++++++++++++------------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index be6655a..de1e6f8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ _This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to w Release notes - Adding the ability to define FROM details for the emails generated by mailGraph - - `smtp_from_address` to set the from mail address (if not set uses mailing system default) + - `smtp_from_address` to set the from mail address (if not set uses mailing system default). Note: obsolete `mail_from` but retained for backwards compatibility. - `smtp_from_name` to set the name that goes with the mail address (if not set uses "mailGraph") ## mailGraph v2.13 release ## diff --git a/config/config.json.template b/config/config.json.template index 271e0cc..7943a54 100644 --- a/config/config.json.template +++ b/config/config.json.template @@ -1,6 +1,5 @@ { "script_baseurl": "https:\/\/mydomain.com\/", - "cli_triggerId": 0, "cli_eventId": 0, "cli_duration": 0, "cli_recipient": "recipient@mydomain.com", @@ -14,7 +13,6 @@ "zabbix_user_pwd": "astrongpassword", "zabbix_api_user": "alogicalusername", "zabbix_api_pwd": "astrongpassword", - "mail_from": "sender@mydomain.com", "subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}", "smtp_server": "localhost", "smtp_port": 25, diff --git a/config/config.json.template.multigraph b/config/config.json.template.multigraph index 88976d6..f1ab5e3 100644 --- a/config/config.json.template.multigraph +++ b/config/config.json.template.multigraph @@ -1,7 +1,5 @@ { "script_baseurl": "https:\/\/mydomain.com\/", - "cli_itemId": 0, - "cli_triggerId": 0, "cli_eventId": 0, "cli_duration": 0, "cli_recipient": "recipient@mydomain.com", @@ -15,12 +13,13 @@ "zabbix_user_pwd": "astrongpassword", "zabbix_api_user": "alogicalusername", "zabbix_api_pwd": "astrongpassword", - "mail_from": "sender@mydomain.com", "subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}", "smtp_server": "localhost", "smtp_port": 25, "smtp_transport": "none", "smtp_strict": "yes", + "smtp_from_address": "mailgraph@mydomain.com", + "smtp_from_name": "mailGraph", "graph_match": "any", "periods": "10m,4h,2d,7d", "periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days", diff --git a/mailGraph.php b/mailGraph.php index f54bec3..46a180e 100644 --- a/mailGraph.php +++ b/mailGraph.php @@ -53,7 +53,7 @@ // Added ability to locate latest problems for testing purposes // 2.12 2023/07/02 - Mark Oudsen - Replaced SwiftMailer with PHPMailer (based on AutoTLS) // 2.13 2023/07/03 - Mark Oudsen - Bugfixes speciifally on links into Zabbix (missing context or info) - // 2.14 2023/07/10 - Mark Oudsen - Adding ability to set 'From' address details in configuration + // 2.14 2023/07/10 - Mark Oudsen - Adding ability to set 'From' address in configuration // ------------------------------------------------------------------------------------------------------ // // (C) M.J.Oudsen, mark.oudsen@puzzl.nl @@ -599,6 +599,15 @@ $p_smtp_from_name = 'mailGraph'; if (isset($config['smtp_from_name'])) { $p_smtp_from_name = $config['smtp_from_name']; } + // >>> Backwards compatibility but smtp_from_address is leading (Sender = $p_smtp_from_address; - $mail->SetFrom($p_smtp_from_address, $p_smtp_from_name, FALSE); - } - else - { - $mail->setFrom($mailFrom, $p_smtp_from_name); - } + $mail->Sender = $p_smtp_from_address; + $mail->SetFrom($p_smtp_from_address, $p_smtp_from_name, FALSE); // --- Add recipient $mail->addAddress($p_recipient);