1
我正在尋找使用bash
和ncat
的解決方案。從this question on ServerFault開始,我已經重新編制了它,mostly this answer,非常基本;允許包含一個CC收件人,使用ncat
而不是netcat
,並將其清理乾淨以便使用(簡單的東西)。正如在這裏看到:使用ncat/netcat/telnet發送多個base64電子郵件附件
# Email Recipient
TOEMAIL="$REPORTRCPT";
# Default Subject
SUBJECT="Build report for $MACHINEFQDN - $DATE @ $DATETIME (PST)";
# Default Contents
MSGBODY="See attachment. Includes all output as seen while running the script.";
# Default Attachment
ATTACHMENT="/tmp/$MACHINENAME-build-$DATE.html"
ATTACHMENT2="/tmp/40_custom-$MACHINENAME-$DATE"
# Default smtp server
mailserver="111.111.111.112"
mailserverPort="25"
fappend() {
echo "$2">>$1;
}
domain=`grep search /etc/resolv.conf | awk '{print $2;}'`
computer=`hostname`
user=`whoami`
FREMAIL="[email protected]$computer.$domain"
MIMETYPE=`file --mime-type -b $ATTACHMENT`
MIMETYPE2=`file --mime-type -b $ATTACHMENT2`
TMP="/tmp/tmpmail_"`date +%N`;
BOUNDARY=`date +%s|md5sum|awk '{print $1;}'`
FILENAME=`basename $ATTACHMENT`
FILENAME2=`basename $ATTACHMENT2`
DATA=`cat $ATTACHMENT|base64`
DATA2=`cat $ATTACHMENT2|base64`
rm $TMP 2> /dev/null
fappend $TMP "EHLO $computer.$domain"
fappend $TMP "MAIL FROM:<$FREMAIL>"
fappend $TMP "RCPT TO:<$TOEMAIL>"
fappend $TMP "RCPT TO:<$REPORTRCPTCC>"
fappend $TMP "DATA"
fappend $TMP "From: $FREMAIL"
fappend $TMP "To: $TOEMAIL"
fappend $TMP "Cc: $REPORTRCPTCC"
fappend $TMP "Reply-To: $FREMAIL"
fappend $TMP "Subject: $SUBJECT"
fappend $TMP "Content-Type: multipart/mixed; boundary=\"$BOUNDARY\""
fappend $TMP ""
fappend $TMP "This is a MIME formatted message. If you see this text it means that your"
fappend $TMP "email software does not support MIME formatted messages."
fappend $TMP ""
fappend $TMP "--$BOUNDARY"
fappend $TMP "Content-Type: text/plain; charset=UTF-8; format=flowed"
fappend $TMP "Content-Disposition: inline"
fappend $TMP ""
fappend $TMP "$MSGBODY"
fappend $TMP ""
fappend $TMP ""
fappend $TMP "--$BOUNDARY"
fappend $TMP "Content-Type: $MIMETYPE; name=\"$FILENAME\""
fappend $TMP "Content-Transfer-Encoding: base64"
fappend $TMP "Content-Disposition: attachment; filename=\"$FILENAME\";"
fappend $TMP ""
fappend $TMP "$DATA"
fappend $TMP ""
fappend $TMP ""
fappend $TMP "--$BOUNDARY--"
fappend $TMP ""
fappend $TMP "."
fappend $TMP "quit"
ncat $mailserver $mailserverPort < $TMP >> $TMP
rc="$?"
if [ "$rc" -ne "0" ]; then
echo "Returncode: $rc"
echo "Please inspect $TMP"
else
echosuccess "Email successfully sent, you should receive it!"
rm $TMP;
fi
但我一直在不斷地嘗試中欺騙它是多個base64
附件。我已經嘗試了各種各樣的東西位置,BOUNDARY
等等,添加了其他變量,如上所示。但是我空了。任何熟悉並能夠伸出援助之手的人?我希望這會像添加CC收件人一樣簡單直接。