Mail Transport use BCC option (#15554)

Option to use BCC instead of to field for emails
This commit is contained in:
Tony Murray
2023-11-08 08:36:09 -06:00
committed by GitHub
parent 7c006e9625
commit 63eeeb7172
2 changed files with 14 additions and 3 deletions

View File

@@ -48,7 +48,7 @@ class Mail extends Transport
$msg = preg_replace("/(?<!\r)\n/", "\r\n", $alert_data['msg']);
}
return \LibreNMS\Util\Mail::send($emails, $alert_data['title'], $msg, $html, $this->config['attach-graph'] ?? null);
return \LibreNMS\Util\Mail::send($emails, $alert_data['title'], $msg, $html, $this->config['bcc'] ?? false, $this->config['attach-graph'] ?? null);
}
public static function configTemplate(): array
@@ -83,6 +83,13 @@ class Mail extends Transport
'type' => 'select',
'options' => $roles,
],
[
'title' => 'BCC',
'name' => 'bcc',
'descr' => 'Use BCC instead of TO',
'type' => 'checkbox',
'default' => false,
],
[
'title' => 'Include Graphs',
'name' => 'attach-graph',

View File

@@ -71,7 +71,7 @@ class Mail
* @param bool $html
* @return bool|string
*/
public static function send($emails, $subject, $message, bool $html = false, ?bool $embedGraphs = null)
public static function send($emails, $subject, $message, bool $html = false, bool $bcc = false, ?bool $embedGraphs = null)
{
if (is_array($emails) || ($emails = self::parseEmails($emails))) {
d_echo("Attempting to email $subject to: " . implode('; ', array_keys($emails)) . PHP_EOL);
@@ -82,9 +82,13 @@ class Mail
foreach (self::parseEmails(Config::get('email_from')) as $from => $from_name) {
$mail->setFrom($from, $from_name);
}
// add addresses
$addMethod = $bcc ? 'addBcc' : 'addAddress';
foreach ($emails as $email => $email_name) {
$mail->addAddress($email, $email_name);
$mail->$addMethod($email, $email_name);
}
$mail->Subject = $subject;
$mail->XMailer = Config::get('project_name');
$mail->CharSet = 'utf-8';