-
Notifications
You must be signed in to change notification settings - Fork 0
/email
executable file
·73 lines (66 loc) · 2.17 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
function usage
{
echo -e "
Usage: $0 -t <Email Recipients> [-f <Email Sender>] [-a \"<Email Attachments>\"] [-s \"<Email Subject>\"] [-b \"<Email Body>\"] [-bf]
$0 -t someemail@here.com -f jobs@here.com -a \"some_data.lis some_data.csv\" -s \"My Message Subject\" -b \"My Message Body\" -bf
Arguments:
-t | --to\t\tEmail To
-f | --from\t\tEmail From
-a | --attach\t\tEmail Attachment Filename(s)
-s | --subject\t\tEmail Subject
-b | --body\t\tEmail Message Body
-bf | --bodyfile\tIndicates the Email Body is the contents of a file
"
}
BODYFILE=0
## Pick up command line arguments
while [ "$1" != "" ]; do
case $1 in
-t | --to ) shift
EMAILTO=$1; export EMAILTO
;;
-f | --from ) shift
EMAILFROM=$1; export EMAILFROM
;;
-a | --attach ) shift
ATTACH=$1; export ATTACH
;;
-s | --subject ) shift
EMAILSUBJECT=$1; export EMAILSUBJECT
;;
-b | --body ) shift
EMAILBODY=$1; export EMAILBODY
;;
-bf | --bodyfile ) BODYFILE=1; export BODYFILE
;;
-h | --help ) usage
exit
;;
* ) echo -e "Unrecognized Parameter Specified: $1"
usage
exit 1
;;
esac
shift
done
## Make sure required variables have been filled.
if [ -z $EMAILTO ]; then
echo "You are missing a required variable."
usage
exit
fi
if [ -n "$EMAILFROM" ]; then
EMAILFROMSTR=" -r $EMAILFROM"
# For OEL 5
# Move variable from before to after $EMAILTO variable
#EMAILFROMSTR=" -- -f $EMAILFROM"
fi
if [ "$BODYFILE" -eq 1 ]; then
EMAILBODY=`cat $EMAILBODY`
fi
if [ -n "$ATTACH" ]; then
(for i in $ATTACH; do uuencode $i $(basename $i); done; echo "$EMAILBODY") | mailx -s "$EMAILSUBJECT" $EMAILFROMSTR "$EMAILTO"
else
echo "$EMAILBODY" | mailx -s "$EMAILSUBJECT" $EMAILFROMSTR "$EMAILTO"
fi