发新话题
打印

unix命令行如何发送附件

unix命令行如何发送附件

  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

TOP

发新话题