मैं इस प्रविष्टि पर डूब गया जब मैं उसी के बारे में कुछ खोज रहा था। और यहाँ के आक्रांताओं से और अतिरिक्त शोध से मैं इस लिपि को बनाने में कामयाब रहा।
#!/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
एक चीज जिसे आप जोड़ना चाहते हैं, वह है प्रमाणीकरण। मुझे इसकी आवश्यकता नहीं है इसलिए मैंने इसे जोड़ा है।
मुझे लगता है कि इसके लिए केवल md5sum , netcat , file , awk और a की आवश्यकता है base64 कमांड्स की आवश्यकता होती है, आईडी अनुमान लगाते हैं कि वे अधिकांश प्रणालियों में बहुत मानक हैं।