Skip to content

Instantly share code, notes, and snippets.

@chuckhoupt chuckhoupt/mailpage.sh
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.