lunedì 21 marzo 2011

Send Mail Using bash shell!

To do this stuff you must install mutt ->

sudo apt-get install mutt


than create a new file and copy:

#!/bin/bash
#
#Require mutt

#check for installation - under construction

#folder=which mutt
#if [ "$folder" == '' ]; then
#   echo "No mutt found"
#else
#   echo "ok"
#exit

if [ -z "$3" ]; then
    echo "#####################################################"
    echo "Mutt shell usage."
    echo "Usage: MailTO [Address] [MailObject] [Attachment y/n]"
    echo "#####################################################"
    exit
fi

echo "Enter Mail text: "
read text
echo $text > mail.txt

if [ "$3" == 'y' ]; then
   echo "Specify attachment folder: "
   read attachment
   if [ -e $attachment ]; then
    mutt -s $2 $1 -a $attachment < mail.txt
    echo "         "
        echo "Mail send"
   else
    echo "$attachment doesn't exists"
   fi

else
   mutt -s $2 $1 < mail.txt
   echo "         "
   echo "Mail send"
fi
data=$(date +%m%d%y)

if [ -d send ]; then
   mv mail.txt send_mail/$data.$2
else
   mkdir send_mail
   mv mail.txt send_mail/$data.$2
fi



Finally...

chmod +x script_name

in sudo mode:


cp script_name /bin/

Nessun commento:

Posta un commento