Created
January 25, 2017 11:42
-
-
Save mrizvic/3457d6b86c6e7dc7fdb4b23301357591 to your computer and use it in GitHub Desktop.
read from stdin and forward as HTML formatted mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
ME=$(basename $0) | |
WORKFILE="/tmp/$ME.$$" | |
if [ ! -z "$MAILTO" ]; then | |
RCPT=$MAILTO | |
else | |
RCPT=$1 | |
fi | |
if [ -z "$RCPT" ]; then | |
echo "USAGE: echo \"ascii art\" | "$ME" [email protected]" | |
echo "Email address can be specified as argument or as environment variable MAILTO" | |
exit 1 | |
fi | |
MAILREGEX="^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$" | |
if [[ ! $RCPT =~ $MAILREGEX ]]; then | |
echo "Check $RCPT address" | |
exit 1 | |
fi | |
INPUT=$(</dev/stdin) | |
cat <<EOF > $WORKFILE | |
From: $RCPT | |
To: $RCPT | |
Subject: izpis | |
Content-Type: text/html; charset="us-ascii" | |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head><title></title></head> | |
<body> | |
<pre> | |
$INPUT | |
</pre> | |
</body> | |
</html> | |
EOF | |
/usr/sbin/sendmail $RCPT < $WORKFILE | |
unlink $WORKFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment