Skip to content

Commit 5a22275

Browse files
authored
Modified to fix email problems on FreeNAS 11.3
1 parent 18dcee7 commit 5a22275

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

ups_report.sh

+14-11
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,28 @@ senddetail=0
1414

1515
freenashost=$(hostname -s)
1616
freenashostuc=$(hostname -s | tr '[:lower:]' '[:upper:]')
17+
boundary="===== MIME boundary; FreeNAS server ${freenashost} ====="
1718
logfile="/tmp/ups_report.tmp"
1819
subject="UPS Status Report for ${freenashostuc}"
1920

2021
### Set email headers ###
21-
(
22-
echo "To: ${email}"
23-
echo "Subject: ${subject}"
24-
echo "Content-Type: text/html"
25-
echo "MIME-Version: 1.0"
26-
printf "\r\n"
27-
) > ${logfile}
22+
printf "%s\n" "To: ${email}
23+
Subject: ${subject}
24+
Mime-Version: 1.0
25+
Content-Type: multipart/mixed; boundary=\"$boundary\"
26+
27+
--${boundary}
28+
Content-Type: text/html; charset=\"US-ASCII\"
29+
Content-Transfer-Encoding: 7bit
30+
Content-Disposition: inline
31+
<html><head></head><body><pre style=\"font-size:14px; white-space:pre\">" >> ${logfile}
2832

2933
# Get a list of all ups devices installed on the system:
3034

3135
upslist=$(upsc -l "${freenashost}")
3236

3337
### Set email body ###
3438
(
35-
echo "<pre style=\"font-size:14px\">"
3639
date "+Time: %Y-%m-%d %H:%M:%S"
3740
echo ""
3841
for ups in $upslist; do
@@ -77,14 +80,14 @@ upslist=$(upsc -l "${freenashost}")
7780
done
7881
) >> ${logfile}
7982

80-
echo "</pre>" >> ${logfile}
83+
printf "%s\n" "</pre></body></html>
84+
--${boundary}--" >> ${logfile}
8185

8286
### Send report ###
8387
if [ -z "${email}" ]; then
8488
echo "No email address specified, information available in ${logfile}"
8589
else
86-
# sendmail -t < ${logfile}
87-
sendmail ${email} < ${logfile}
90+
sendmail -t -oi < ${logfile}
8891
rm ${logfile}
8992
fi
9093

0 commit comments

Comments
 (0)