-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmail.sh
executable file
·57 lines (49 loc) · 1.38 KB
/
sendmail.sh
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
#!/bin/bash
# defaults
from="$(printf "no-reply@$HOSTNAME" )"
to=""
cc=""
bcc=""
date=$(date -R)
subject=""
message=$(cat)
TEMP=`getopt -o f:t:s:d: --long from:,to:,cc:,bcc:,subject:,date: -n "$0" -- "$@"`
if [ $? != 0 ] ; then echo "Abandon" >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
while true ; do
case "$1" in
-f|--from) from=$2; shift 2;;
-s|--subject) subject=$2; shift 2;;
-d|--date) date=$2; shift 2;;
-t|--to) if [ "$to" == "" ]
then
to=$2
else
to="$to,$2"
fi
shift 2;;
--cc) if [ "$cc" == "" ]
then
cc=$2
else
cc="$cc,$2"
fi
shift 2;;
--bcc) if [ "$bcc" == "" ]
then
bcc=$2
else
bcc="$bcc,$2"
fi
shift 2;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
done
if [ "$to" == "" ]
then
echo "At least one recipient is needed." >&2
exit 1
fi
printf "From: %s\nTo: %s\nCC: %s\nBcc: %s\nDate: %s\nSubject: %s\nContent-Type: text/html; charset=\"UTF-8\"\n%s\n" "$from" "$to" "$cc" "$bcc" "$date" "$subject" "$message" | msmtp -t