リハビリテスト記事
必要なコマンドセット
bash
とcut
だけ
スクリプト
#!/bin/bash -eux
_waitStatus(){
while true;do
read status <&3
if [[ "$1" == "$(echo "$status" | cut -d' ' -f1)" ]];then
break
fi
done
}
exec 3<> /dev/tcp/${MAILSERVERADDR}/25
_waitStatus 220
echo "HELO ${MAILSERVER}" >&3
_waitStatus 250
echo "MAIL FROM: <${MAILFROM}>" >&3
_waitStatus 250
echo "RCPT TO: <$1>" >&3
_waitStatus 250
echo "DATA" >&3
_waitStatus 354
echo "From: ${MAILFROM}" >&3
echo "Subject: $2" >&3
echo "" >&3
echo "$3" >&3
echo "." >&3
exec 3<&-
HowTo
下記のように実行する
$ export MAILSERVER=example.com
$ export MAILFROM=anya@example.com
$ export MAILSERVERADDR=smtp.example.com
$ ./sendmail.sh "rubbish@anya.jp" "Hello my bro!" "This is test mail at $(date)."
以上