日期:2014-05-16  浏览次数:20723 次

咨询下,关于shell发邮件的问题
大家好,以下是我从网上找的代码进行的修改。
目前的现象是:可以收到邮件,但是没有主题没有附件没有正文。

我也查询过,按http://topic.csdn.net/u/20110413/15/366E6BB8-296C-4B10-BCC1-FFC41E3D3B90.html
里的运行,我这边收不到邮件。

现在想实现的就是:有主题,有正文(正文也可以坐直接是附件的内容,这样不需要附件也可以的)

请指点,谢谢!!


C# code
#!/bin/sh
# shell_mailer.sh, Shell Mailer, (MTA)
# #---------------------
# # Variables
# #--------------------- 

mailfile=test.txt

sender=aaa@bbb 
reciver=aaa@bbb 
email_content_txt=$mailfile 
smtp='mail.bbb' 

subject='test' 

#if [ "$#" != 4 ]; then
 #echo "Usage: $0 mailsender@doamin.com mailrecieve@domain.com subject text_file"
 #exit 2
#fi


mesge(){
cat << EOF
From: <$sender>
To: <$reciver>
Subject: $subject
Date: `date` +0800
Mime-Version: 1.0
ontent-Type: text/plain; charset="us-ascii"; format=flowed
X-Mailer: Solaris Mail Client
X-MimeOLE: Powered by Solaris 


EOF
test -r $email_content_txt && cat $email_content_txt
}

send_mail(){
(
 sleep 5
 for comm in "helo 163.com" "mail from:<$sender>" "rcpt to:<$reciver>" "data"
 do
 echo "$comm"
 sleep 3
 done
 #mesge
 sleep 3
 echo ".")| telnet $smtp 25
} 



send_mail 



------解决方案--------------------
test.txt里写:
From: <$sender>
To: <$reciver>
Subject: $subject
Date: `date` +0800
Mime-Version: 1.0
ontent-Type: text/plain; charset="us-ascii"; format=flowed
X-Mailer: Solaris Mail Client
X-MimeOLE: Powered by Solaris
正文内容xxxx

mesge(){
cat test.txt
}
这样会收不到?