aboutsummaryrefslogtreecommitdiff
path: root/bin/email
diff options
context:
space:
mode:
Diffstat (limited to 'bin/email')
-rwxr-xr-xbin/email31
1 files changed, 23 insertions, 8 deletions
diff --git a/bin/email b/bin/email
index 87d1cec..d427770 100755
--- a/bin/email
+++ b/bin/email
@@ -4,7 +4,7 @@ set -eu
usage() {
cat <<-'EOF'
Usage:
- email -s SUBJECT ADDRESS... < BODY
+ email [-s SUBJECT] [-f FROM] ADDRESS... < BODY
email -h
EOF
}
@@ -13,7 +13,8 @@ help() {
cat <<-'EOF'
Options:
- -s SUBJECT the email subject
+ -s SUBJECT the email subject (default: "CLI email: No subject")
+ -f FROM the addr to send from (default: "eu@euandre.org")
-h, --help show this message
ADDRESS the email addresses to send the email to
@@ -46,8 +47,13 @@ for flag in "$@"; do
esac
done
-while getopts 's:h' flag; do
+FROM='eu@euandre.org'
+SUBJECT='CLI email: No subject'
+while getopts 'f:s:h' flag; do
case "$flag" in
+ f)
+ FROM="$OPTARG"
+ ;;
s)
SUBJECT="$OPTARG"
;;
@@ -64,10 +70,19 @@ while getopts 's:h' flag; do
done
shift $((OPTIND - 1))
+ADDRESS="${1:-}"
+
eval "$(assert-arg "${SUBJECT:-}" '-s SUBJECT')"
-eval "$(assert-arg "${1:-}" 'ADDRESS')"
+eval "$(assert-arg "$ADDRESS" 'ADDRESS')"
-printf 'Content-Type: text/plain; charset=UTF-8\nSubject: %s\n\n%s' \
- "$(echo "$SUBJECT" | tr -d '\n')" \
- "$(cat)" |
- msmtpq -a EuAndreh "$@"
+{
+ cat <<-EOF
+ Content-Type: text/plain; charset=UTF-8
+ Content-Transfer-Encoding: 8bit
+ From: $FROM
+ To: $ADDRESS
+ Subject: $(echo "$SUBJECT" | tr -d '\n')
+
+ EOF
+ cat -
+} | sendmail -tf "$FROM"