カテゴリ:スクリプト
以下のようなスクリプトを書いてみました。 備忘録として、アップしておきます。 #!/usr/local/bin/bash
cat< Usage: $0 FromAddress ToAdress Subject Attachement --- FromAddress is This mail Sender. ToAdress is Sendto this Mail. Subject is Mail Subject Attachement is Atachement file name. EOM } if [ $# -ne 4 ];then if [ ${DEBUG} ];then echo "!! DEBUG:\$# is $#" >&2 fi PrintUsage exit 1 fi if [ ${DEBUG} ];then echo "\${1} is ${1}" echo "\${2} is ${2}" echo "\${3} is ${3}" echo "\${4} is ${4}" fi ## Init section FADRES="${1}" TADRES="${2}" SUBJECT="${3}" BOUNDARY=`date "+%Y%m%d%H%M%N"` ARCVNAME="${4}" FILENAME=`echo "${4}" | sed -e "s/.*\/\(.*$\)/\1/"` CONTTYPE=`file --mime ${4} | cut -d' ' -f2` MAIL_TMP=".MIME_MAIL.tmp" if [ ${DEBUG} ];then echo "\${FADRES} is ${FADRES}" echo "\${TADRES} is ${TADRES}" echo "\${SUBJECT} is ${SUBJECT}" echo "\${BOUNDARY} is ${BOUNDARY}" echo "\${CONTTYPE} is ${CONTTYPE}" echo "\${FILENAME} is ${FILENAME}" echo "\${MAIL_TMP} is ${MAIL_TMP}" exit 99 fi PrintScale(){ cat< 0--------1---------2---------3---------4---------5---------6---------7---------8 12345678901234567890123456789012345678901234567890123456789012345678901234567890 EOSCALE } PrintMailHeader(){ cat< From: $FADRES To: $TADRES Subject: $SUBJECT MIME-Version: 1.0 Content-type: multipart/mixed; boundary="----${BOUNDARY}" Content-Transfer-Encoding: 7bit This is a multi-part message in MIME format. EOHEAD } PrintMailBody(){ cat< ------${BOUNDARY} Content-type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Generated by ${0} on `date "+%Y/%m/%d %H:%M:%S"` EOBODY } PrintAttachFile(){ cat< ------${BOUNDARY} Content-type: ${CONTTYPE} name=${FILENAME} Content-Transfer-Encoding: base64 Content-Disposition : attachment; filename=${FILENAME} `b64encode ${ARCVNAME} ${FILENAME}` ------${BOUNDARY}-- EOA } # ================================================================== ## generate MIME encoded mail touch ${MAIL_TMP} PrintMailHeader >> ${MAIL_TMP} ## Insert MAIL_BODY (if you need) PrintMailBody >> ${MAIL_TMP} PrintScale >> ${MAIL_TMP} ## Attach file PrintAttachFile >> ${MAIL_TMP} ## Send E-Mail # /usr/sbin/sendmail -i $TADRES < ${MAIL_TMP} if [ ${DEBUG} ];then cat ${MAIL_TMP} exit 9 fi sendmail -t < ${MAIL_TMP} ## Delete TEMP file rm -f ${MAIL_TMP} exit 0 お気に入りの記事を「いいね!」で応援しよう
最終更新日
2011.01.24 15:52:23
コメント(0) | コメントを書く
[スクリプト] カテゴリの最新記事
|