Ben aynı bir şey ararken ben bu giriş üzerine yuvarlandı. ve burada filizler ve som bir ek araştırma ben bu senaryo yapmak başardı.
#!/bin/sh
# Default reception
TOEMAIL="myEmail@domain.ltd";
# Default Subject
SUBJECT="You got mail - $DATE";
# Default Contents
MSGBODY="Hello, this is the default message body";
# Default Attachment
#ATTACHMENT="/tmp/testoutput"
# Default smtp server
mailserver="smtp.server.ltd"
mailserverPort="25"
showUsage() {
echo "$0 -a /file/to/attach [-m /message/file] [-M \"Message string\"] -s \"subject\" -r receiver@domain.com"
echo
echo "The attachment (-a) is required, if no attachment is used then rather use sendmail directly."
}
fappend() {
echo "$2">>$1;
}
DATE=`date`
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# This might need correction to work on more places, this is tested at a ubuntu 13.10 machine. #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
domain=`grep search /etc/resolv.conf | awk '{print $2;}'`
computer=`hostname`
user=`whoami`
FREMAIL="$user@$computer.$domain"
while getopts "M:m:a:s:r:" opt; do
case $opt in
s)
SUBJECT="$OPTARG - $DATE"
;;
r)
TOEMAIL="$OPTARG"
;;
m)
MSGBODY=`cat $OPTARG`
;;
M)
MSGBODY="$OPTARG"
;;
a)
ATTACHMENT="$OPTARG"
;;
:)
showUsage
;;
\?)
showUsage
;;
esac
done
if [ "$ATTACHMENT" = "" ]; then
showUsage
exit 1
fi
MIMETYPE=`file --mime-type -b $ATTACHMENT`
TMP="/tmp/tmpmail_"`date +%N`;
BOUNDARY=`date +%s|md5sum|awk '{print $1;}'`
FILENAME=`basename $ATTACHMENT`
DATA=`cat $ATTACHMENT|base64`
rm $TMP 2> /dev/null
fappend $TMP "EHLO $computer.$domain"
fappend $TMP "MAIL FROM:<$FREMAIL>"
fappend $TMP "RCPT TO:<$TOEMAIL>"
fappend $TMP "DATA"
fappend $TMP "From: $FREMAIL"
fappend $TMP "To: $TOEMAIL"
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"
netcat $mailserver $mailserverPort < $TMP >> $TMP
rc="$?"
if [ "$rc" -ne "0" ]; then
echo "Returncode: $rc"
echo "Please inspect $TMP"
else
rm $TMP;
fi
Eklemek isteyebileceğiniz bir şey kimlik doğrulamadır. i gerek yok bu yüzden ekledi sığınak.
Ben sadece md5sum , netcat , dosya , awk ve base64 komutları gerektirir düşünüyorum , id sanırım çoğu sistemde oldukça standarttır.