您的位置:首页 > 运维架构 > Shell

Sent mail -Shell:Mark 一下。

2013-11-15 10:59 399 查看












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

位置參數:/article/10440846.html

shell 變量:http://blog.csdn.net/u010300484/article/details/8818055
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: