#
#
# email_report()
#
#
# include "templates.util.base_util";
subroutine(email_report(
node email_info,
string report_content), (
debug_message("\n\n#### email_report() \n");
debug_message("\n" . node_as_string(email_info) . "\n");
# Invoked from command_line_report.cfv and from dynamic reports
# email_info contains all email parameters. At this point we don't have
# to check for valid email parameters, they have already been validated.
# The node volatile.mime_images_buffer should be already set,
# it has been populated in assemble_static_report.cfv
# debug_message("#### Final volatile.mime_images_buffer START \n". volatile.mime_images_buffer . "\n");
# debug_message("#### Final volatile.mime_images_buffer END \n");
# debug_message("#### report_content START \n" . report_content . "\n");
# debug_message("#### report_content END \n");
subroutine(get_cleaned_up_email_address(
string email_address), (
# This cleans email addresses from older ", " separators in scheduler by
# removing the space after the comma because they cause problems in
# some email servers.
if (email_address ne "" and contains(email_address, ", ")) then (
email_address = replace_all(email_address, ", ", ",");
);
# Return
email_address;
));
string smtp_server = @email_info{"smtp_server"};
string smtp_username = @email_info{"smtp_username"};
string smtp_password = @email_info{"smtp_password"};
string return_address = @email_info{"return_address"};
string to_address = get_cleaned_up_email_address(@email_info{"recipient_address"});
string cc_address = get_cleaned_up_email_address(@email_info{"cc_address"});
string bcc_address = get_cleaned_up_email_address(@email_info{"bcc_address"});
string report_email_subject = get_expanded_string(@email_info{"report_email_subject"});
string comment = @email_info{"comment"};
# Note, recipient_address, cc_address and bcc_address may contain multiple
# email addresses separated by a comma.
string all_recipient_addresses = "";
string message = "From: " . return_address . "\n";
if (to_address ne "") then (
message .= "To: " . to_address . "\n";
all_recipient_addresses .= to_address . ",";
);
if (cc_address ne "") then (
message .= "Cc: " . cc_address . "\n";
all_recipient_addresses .= cc_address . ",";
);
if (bcc_address ne "") then (
message .= "Bcc: " . bcc_address . "\n";
all_recipient_addresses .= bcc_address . ",";
);
all_recipient_addresses = replace_last(all_recipient_addresses, ",", "");
debug_message("#### all_recipient_addresses: " . all_recipient_addresses . "\n");
message .= "Subject: " . report_email_subject . "\n";
message .= "\n";
# debug_message("#### Email header\n: " . message . "\n\n");
if (comment ne "") then (
# Insert the comment into the report_content string by replacing
# the body element.
# Maintain line breaks
if (contains(comment, "\n")) then (
comment = replace_all(comment, "\n", "
");
);
string comment_as_html = '