-
Notifications
You must be signed in to change notification settings - Fork 1
/email
executable file
·58 lines (46 loc) · 1.09 KB
/email
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
#---------------------------------------------------------------------
usage ()
{
cat <<EOT
${0##*/}
Provides a simplified interface for sending email from the local
system, with the goal of being able to fail gracefully when the
\`mail\` executable is not available.
Usage:
bin/${0##*/} <emailAddress> <subject> <msgBodyFile>
- emailAddress: The email address to which to send the message.
- subject: The subject line to use for the message.
- msgBodyFile: The full path to the text file containing the message body.
EOT
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
}
if [ "$1" = '-h' ]; then
usage
fi
# Variable initialization.
MAIL="$( which mail )"
if [ $? -gt 0 ]; then
echo "!! Unable to locate the 'mail' executable. !!"
echo ""
exit 1
fi
# Input processing.
if [ -n "$1" ]; then
ADDRESSES=$1
else
usage
fi
if [ -n "$2" ]; then
SUBJECT=$2
else
usage
fi
if [ -r "$3" ]; then
MESSAGE_FILE=$3
else
usage
fi
echo "## Sending email to: ${ADDRESSES}.";
${MAIL} -s "${SUBJECT}" "${ADDRESSES}" < "${MESSAGE_FILE}"
exit $?