Info

  • demo post

bash_send_mail.sh

chmod a+x bash_send_mail.sh
./bash_send_mail.sh subject messages

Script

#!/bin/bash

DOMAIN="thfree.ru"
MXDOMAIN="mail.$DOMAIN"
PORT=25

HEADLINE=100

SUB="$1"
LOGFILE="$2"

if [ "$SUB" = "" ]; then
  exit 1
fi

if [ "$LOGFILE" != "" ]
 then
  MESSLOG=`head -n $HEADLINE $LOGFILE`
else
  MESSLOG=$SUB
fi

exec 1<>/dev/tcp/$MXDOMAIN/$PORT
a=("
HELO $MXDOMAIN
MAIL FROM: <no-reply@$DOMAIN>
RCPT TO: <admin@$DOMAIN>
DATA
From: no-reply@$DOMAIN
To: admin@$DOMAIN
Subject: $SUB
$MESSLOG
.
QUIT
.
")
IFS='
'
declare -a b=($a)
for x in "${b[@]}"
 do
   echo $x
   sleep .1
done