Created
December 13, 2013 12:47
-
-
Save f81/7943760 to your computer and use it in GitHub Desktop.
[bash] CentOS添付ファイル付きメール送信(sendmail)の実装 ref: http://qiita.com/f81@github/items/6ef614c6e88b9d17c41f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/sh | |
# commands. | |
SENDMAIL=/usr/lib/sendmail | |
ECHO=/bin/echo | |
GZIP=/bin/gzip | |
CAT=/bin/cat | |
RM=/bin/rm | |
# attachment file info. | |
ATTACH_FILE=attachmail.txt | |
ATTACH_PATH=/tmp/$ATTACH_FILE | |
# mail head settings. | |
MAIL_BODY=/tmp/mail_body.txt | |
MAIL_FROM=xxx@abc.com | |
MAIL_TO=yyy@abc.com | |
MAIL_SUBJECT="TEST ATTACHMENT MAIL." | |
MAIL_BOUNDARY=`date +%Y%m%d%H%M%N` | |
# make attachment file (test data). | |
$ECHO "1,2,3,4,5" > $ATTACH_PATH | |
$ECHO "6,7,8,9,10" >> $ATTACH_PATH | |
# attachment compression. | |
cd /tmp | |
$GZIP $ATTACH_FILE | |
#make body. | |
$ECHO "this is Body." > $MAIL_BODY | |
# send mail. | |
$SENDMAIL -t << EOF | |
From: ${MAIL_FROM} | |
To: ${MAIL_TO} | |
Subject: ${MAIL_SUBJECT} | |
MIME-Version: 1.0 | |
Content-type: multipart/mixed; boundary=${MAIL_BOUNDARY} | |
Content-Transfer-Encoding: 7bit | |
--${MAIL_BOUNDARY} | |
Content-type: text/plain; charset=iso-2022-jp | |
Content-Transfer-Encoding: 7bit | |
`${CAT} ${MAIL_BODY}` | |
--${MAIL_BOUNDARY} | |
Content-type: application/zip; | |
name=${ATTACH_FILE}.gz | |
Content-Transfer-Encoding: base64 | |
Content-Disposition : attachment; | |
filename=${ATTACH_FILE}.gz | |
`${CAT} ${ATTACH_PATH}.gz | base64` | |
--${MAIL_BOUNDARY}-- | |
EOF | |
$RM -fr ${ATTACH_PATH}.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment