Sent mail -Shell:Mark 一下。

来源:互联网 发布:cf软件制作 编辑:程序博客网 时间:2024/06/05 01:00






shell发送邮件(smtp)

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

sender=$1 # 发信人的email
reciver=$2 # 收信人的email
subject=$3 # 邮件的标题
email_content_txt=$4 # 存放邮件内容的文件
smtp='mail.163.com' # 修改这里,邮件服务器地址

if [ "$#" != 4 ]; then
   echo "Usage: $0 mailsender@doamin.commailrecieve@domain.comsubject text_file"
   exit 2
fi
# text_file的内容为邮件正文

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

# # 邮件使用了ASCII编码,而非BASE64,这可以保证存储邮件正文的文件中直接使用常见的ASCII明文进行编辑
#
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

#Mail



Reference :http://hi.baidu.com/h_weboo/item/090115d43e6ffa1620e25034

位置參數:http://blog.csdn.net/yunccll/article/details/2651616
shell 變量:http://blog.csdn.net/u010300484/article/details/8818055


原创粉丝点击