写了自动发送邮件的shell

写了自动发送邮件的shell

我想通过telnet mailserver 25去自动发送邮件,可是我发现不可阿~老是抱错哦。请大家帮我看看。。以前ftp都可以自动登录的。
:mad:
[CODE]
#!/bin/sh
if [ $# -ne 1 ];then
echo -e "need ip...."
exit
fi
telnet $1 25 <<AUTO                        #$1 is mail server ip
sleep 2s
mail from:<[email="test@mail.com"]test@mail.com[/email]>
sleep 1s
rcpt to:<[email="123@mail.com"]123@mail.com[/email]>
sleep 1s
data
hahahaha>>>>>>>>>>>>>>>
         :-)
hahahaha>>>>>>>>>>>>>>>
.
quit
AUTO
if [ $? -eq 0 ];then
echo -e "mail success\n"
else
echo -e "mail failed\n"
fi[/CODE]


报错:
Trying 192.168.0.111...
Connected to 192.168.0.111.
Escape character is '^]'.
Connection closed by foreign host.
mail failed      
you need not connect to smtp port manually. there are many convenient tools that can send out mails.      
/usr/sbin/sendmail $mailto <<EOF
From: [email="test@mail.com"]test@mail.com[/email]
To: $mailto
Subject : $title
hahahaha>>>>>>>>>>>>>>>
         :-)
hahahaha>>>>>>>>>>>>>>>

EOF      
这样是可以了,可是你可以发现,我不能够指定server去发送mail了。
能解决这个问题么?