쉘 상에서 별다른 메일 클라이언트를 쓰지 않고 간단히 첨부파일을
포함한 메일을 보내는 스크립트를 만들었습니다. 너무 허접하자만
전 잘 쓰고 있어요.
사용법은...
[root@www /root]# amail zoo11 at aw23.com tel
Subject: test for att. file
From (Enter for root at www.xxcas.com): damn at damn.com Write your messages here. End with CTRL-D
test.
ok?
Sending...Done.
[root@www /root]#
#!/bin/sh
trap 'rm -f /tmp/amail*.tmp 1> /dev/null 2>&1 ; exit 1' 0 1 2 15
MAILTO=$1
ATTFILE=$2
HOST=`hostname -f`
MIME=`type -path mimencode` 2> /dev/null
ME=`basename $0`
SMAIL=`type -path sendmail` 2> /dev/null
if [ -z $SMAIL ] ; then
echo "sendmail does not exist in your PATH! Quit..." ; exit 1
fi
if [ -z $MIME ] ; then
echo "mimencode does not exist in your PATH! Quit..." ; exit 1
fi
if [ $# -ne 2 ] ; then
echo "Usage:$ME <mailto> <attfile>" ; exit 1
fi
if [ ! -f $ATTFILE ] ; then
echo "A file $ATTFILE does not exist or not a regular file. Quit..." ; exit 1
fi
echo -n "Subject:"
read SUBJ
echo -n "From (Enter for $USER@$HOST): "
read FROM
if [ -z $FROM ] ; then
FROM=$USER@$HOST
fi
echo "Write your messages here. End with CTRL-D"
cat > /tmp/amail.tmp 2> /dev/null
$MIME $ATTFILE > /tmp/amailat.tmp 2> /dev/null
cat > /tmp/amailfi.tmp << _EOF
MIME-Version:1.0
Content-Type: multipart/mixed; boundary="zYM0uCDKw75$$"
Content-Disposition: inline
From:$FROM
Subject:$SUBJ
--zYM0uCDKw75$$
Content-Type: text/plain
Content-Disposition: inline
`cat /tmp/amail.tmp`
--zYM0uCDKw75$$
Content-Type: application/octet-stream; name="`basename $ATTFILE`"
Content-Transfer-Encoding: base64
`cat /tmp/amailat.tmp`
_EOF
echo -n "Sending..."
$SMAIL $MAILTO < /tmp/amailfi.tmp && echo "Done."--God save the queen.