3 ## Copyright (C) 2007 - 2010 Steve Youngs
5 ## Time-stamp: <Friday Oct 15, 2010 22:17:02 steve>
7 ## Redistribution and use in source and binary forms, with or without
8 ## modification, are permitted provided that the following conditions
11 ## 1. Redistributions of source code must retain the above copyright
12 ## notice, this list of conditions and the following disclaimer.
13 ## 2. Redistributions in binary form must reproduce the above copyright
14 ## notice, this list of conditions and the following disclaimer in the
15 ## documentation and/or other materials provided with the distribution.
16 ## 3. Neither the name of the University nor the names of its contributors
17 ## may be used to endorse or promote products derived from this software
18 ## without specific prior written permission.
20 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 ## IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 ## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 ## DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 ## BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 ## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 ## OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30 ## IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 # This is a simple wrapper around sendmail that serves as a command
36 # line mailer, along the lines of mailx or nail.
43 COPYRIGHT="Copyright (C) 2007 - 2010 Steve Youngs <steve@steveyoungs.com>"
44 version_str="${ourname}: ${VERSION}
47 _version () { echo $version_str }
61 [ -F FROM | --from=FROM ] [ -s SUBJECT | --subject=SUBJECT ]
62 [ -c CC[,...CCn] | --cc=CC[,...CCn] ] [ -f FILE | --file=FILE ]
63 RECIPIENT[,...RECIPIENTn]
65 [ -v | --version ] [ -h | --help | --usage ]
70 $ourname is a simple command line mailer. It is not really meant as
71 a replacement for something better like mailx or nail, but it should
72 suffice until you install a more feature rich mailer. The author
73 uses SXEmacs/Gnus for day to day email, and this script for any
81 Specify an alternate From address. If omitted, try the
82 environment variable EMAIL, fall back to:
87 Specify a Subject header. If omitted, "No Subject given" will
92 Optional addresses to include on a Cc header.
96 A plain text file containing the body of the email message.
97 If this option is omitted, stdin is used. This option should
98 always be the last on the command line.
109 Environment Variables:
110 ---------------------
112 EMAIL -- To set a From address. Maybe necessary if your publically
113 known email address is different from your system default.
121 # Process the mail's headers
124 local MTA=/usr/sbin/sendmail
127 { FROM=${EMAIL} && [[ -n ${FROM} ]] || FROM=${USER}@$(hostname -f) }
129 [[ -n ${SUBJECT} ]] || SUBJECT="No Subject given"
133 [[ -n ${CC} ]] && echo "Cc: ${CC}"
134 echo "From: <${FROM}>"
135 echo "Date: $(date --rfc-2822)"
136 echo "Subject: ${SUBJECT}"
137 echo "User-Agent: bastard mailer, ${VERSION}"
144 # Parse the command line
148 while getopts $args opts; do
152 (from?*) FROM=${OPTARG/from=/} ;;
153 (subject?*) SUBJECT=${OPTARG/subject=/} ;;
154 (cc?*) CC=${OPTARG/cc=/} ;;
155 (file?*) FILE=${OPTARG/file=/} ;;
156 (version) _version; exit 0 ;;
157 (help|usage) usage; exit 0 ;;
159 print Unrecognised option: --$OPTARG >&2
160 print See $ourname --help >&2
165 (F) FROM=${OPTARG} ;;
166 (s) SUBJECT=${OPTARG} ;;
168 (f) FILE=${OPTARG} ;;
169 (v) _version; exit 0 ;;
172 print Unrecognised option -$OPTARG >&2
173 print see $ourname --help >&2
178 shift $(( $OPTIND - 1 ))
180 # What's left on the command line _should_ be the recipients
183 if [[ $rv -eq 0 ]]; then