if [ -x /usr/sbin/sendmail ]; then
SENDMAIL_PATH="/usr/sbin/sendmail"
elif [ -x /usr/lib/sendmail ]; then
SENDMAIL_PATH="/usr/lib/sendmail"
else
echo "sendmail not found."
exit 1
fi
FROM_ADDRESS="anmino@abc.com"
FROM_REALNAME="サンプル"
LF='
'
if echo x | read -r 2> /dev/null; then
READ_R="-r"
else
READ_R=""
fi
tohex(){
od -x | head -1 | sed -e 's/[^ ]*//' -e 's/ //g'
}
msgid(){
datestr=`date +%Y%m%d.%H%M%S`
random=`dd if=/dev/random bs=8 count=1 2> /dev/null | tohex`
domain=`expr "$FROM_ADDRESS" : ".*@\(.*\)"`
echo "$datestr-$$-$random@$domain"
}
fixheader(){
header=""
while read $READ_R line; do
[ -z "$line" ] && break
header="$header$line$LF"
done
if echo "$header" | grep -qi '^from:'; then
else
header="${header}From: $FROM_REALNAME <$FROM_ADDRESS>$LF"
fi
if echo "$header" | grep -qi '^message-id:'; then
else
header="${header}Message-Id: <`msgid`>$LF"
fi
echo "$header"
cat
}
if [ "$1" = "--send" ]; then
emit="SENDMAIL_PATH -t -f $FROM_ADDRESS"
shift
else
emit="cat"
fi
if [ -n "$1" ]; then
echo "Usage: mail_send.sh [--send]"
exit 1
fi
fixheader | nkf -j | enMine | $emit