您的位置:首页 > 文档 > Shell >
 文章分类 

unix命令行如何发送附件


创建:2005-10-26 00:49:45
作者:Unlinux
来自: http://www.Unlinux.com

The script show how to send mail with attachment in UNIX.

The attchment is an ascii file.(Binary file should have another tool to convert it) .

#!/bin/ksh

#mail infomation
filename=test.csv
subject="test email with attachment"
body="This is a test mail."
MAILFROM=rollingpig@163.com
MAILTO=serol_luo@gmail.com

#boundary is random string to seperate parts of mail
boundary=396d983d6b89a
#temporay file,to store mail content
tmpfile=/tmp/a.tmp

cat > $tmpfile <<EOF
Return-Path: <$MAILFROM>
From:<$MAILFROM>
To:<$MAILTO>
Content-type: multipart/mixed; boundary="$boundary"
Subject: $subject

--396d983d6b89a
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8bit

$body

--$boundary
Content-disposition: inline; filename=$filename

EOF

cat $filename >>$tmpfile
echo --$boundary-- >> $tmpfile
mail $MAILTO < $tmpfile

转载自:http://www.unlinux.com/doc/shell/20051026/226.html

评论】 【加入收藏夹】 【 】 【打印】 【关闭
 *  请尊重我们的劳动,转载请注明出自UnLinux.Com及作者名 * 

※ 相关链接
 ·Unix awk使用手册  (2005-10-26 00:49:45)
 ·Unix Shell 介绍  (2005-10-26 00:49:45)
 ·也谈在Unix系统中杀死相关终端的进程  (2005-10-26 00:49:44)
 ·也谈在Unix系统中杀死相关终端的进程  (2005-10-26 00:49:44)
 ·SCO UNIX 5.0.5下通用菜单程序(用bsh制作,含源码)  (2005-10-26 00:49:44)

Copyright © 2005 UnLinux.Com All Rights Reserved