Skip to content

Instantly share code, notes, and snippets.

@chuckhoupt
Last active June 18, 2021 19:57
Show Gist options
  • Save chuckhoupt/9468064 to your computer and use it in GitHub Desktop.
Save chuckhoupt/9468064 to your computer and use it in GitHub Desktop.
Bash shell script to mail a copy of a web page's HTML so it will render correctly in most native email programs (but not in web-mail).
#!/bin/bash
# Examples:
#
# mailpage.sh http://example.com chuck@habilis.net 'An Example Page'
# mailpage.sh http://example.com chuck@habilis.net 'Passworded Page' --user=john --password=xxxxx
set -eu
USAGE=$'\n'"Usage: $(basename $0) URL address subject [ wget options ]"
URL=${1:?"Missing URL.$USAGE"}
ADDRESS=${2:?"Missing Address.$USAGE"}
SUBJECT=${3:?"Missing Subject.$USAGE"}
shift 3
WGET_ARGS="$@"
OUT=$(mktemp)
trap 'rm -f "$OUT"' EXIT
wget --no-verbose --convert-links --output-document="$OUT" $WGET_ARGS "$URL" 2>&1
mail -a 'MIME-Version: 1.0' -a 'Content-type: text/html; charset=utf-8' -s "$SUBJECT" "$ADDRESS" < "$OUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment