Blastmail with shell script version 3.1

#!/bin/bash
##=================================================================##
 file ini berisi perintah untuk mengirimkan email        
 Created By   : Yudi Ariestya Putranto                          
 email             : yudi.ariestya@live.com                          
 Version          : 3.1                           
 Date              : April 2013                                      
 Lihat Readme untuk penggunaan lengkap nya              
##=================================================================##

*** P E N T I N G  ***
1. lakukan penyesuaian path terlebih dahulu ya
2. setting DNS anda sampai MX dan DNS nya berfungsi dengan baik
3. install postfix dan lakukan penyesuaian standard
4. klo di copas tolong di cantumkan alamat blog saya ya, biar saya juga terkenal
5. yang baru liat blog ini, coba pelajari dulu ya dari blastmail versi 1.0  blastmail versi 3.0 ====================================================================

dalam versi 3.1 ini saya lakukan beberapa penyempurnaan untuk aplikasi blastmail ini, antara lain adalah
1. Saya menggabungkan kirim.sh dan kirimdebug.sh dan menggantinya dengan menggunakan parameter
2. penambahan parameter -help , -d , -g , -i , -v yang mempunyai masing2 fungsi
3. saya menambahkan file help yang berisi tutorial aplikasi ( filenya isi sendiri ya, klo gak sempet copas aja)

berikut yang bisa di copas

VER="4.0"
NOW=$(date +"%Y%m%d")
SUBJECT=$1
PENERIMA=$3
PARAMETER=$2
    echo $SUBJECT,$NOW > /opt/blastmail/subject
    echo "${PENERIMA,,}",$NOW > /opt/blastmail/penerima

# make sure file exits for reading
function cek_parm
{
    if [ ! -f /opt/blastmail/body/*.html ]; then
    echo "File html tidak ada" ; exit 1
        fi
           if [ ! -f /opt/blastmail/recipient/"${PENERIMA,,}" ]; then
              echo "$0: invalid option -- $PENERIMA"; echo "Gunakan bantuan  $0 -help" ; exit 1
              fi
                if [ ! -f /opt/blastmail/recipient/*.csv ];then
                   echo "File Penerima (*.csv) tidak ada"; exit 1
                   fi
    }

function cek_parm2
{
     if [ ! -f /opt/blastmail/recipient/"${PENERIMA,,}" ]; then
        echo "Filename "${PENERIMA,,}" does not exists" ; exit 1
          fi

}
GENLOG ()
   {
        date +"Status email = terkirim : %b %d %H:%M:%S %Y"  >> /opt/blastmail/log/counter.log
            hitung=$(cat /opt/blastmail/log/counter.log|grep "Status email"|wc -l)
                echo Total = $hitung Email >> /opt/blastmail/log/counter.log
   }

REPORT ()
   {
    for MAILTO in `cat /opt/blastmail/recipient/coba`
    do
        NOW=$(date +"%Y%m%d")
        SUBJECT=$( cat subject | grep $NOW |awk -F "," '{print $1}'| sed -e "s/ //g" )
        hitung=$(cat /opt/blastmail/log/counter.log|grep "Status email"| wc -l)
        export FROM="cs@karir.com"
        export SUBJECT="Newsletter Report $NOW"
        (
             echo "To: $MAILTO"
             echo "From: $FROM"
             echo "Subject: $SUBJECT"
             echo Dear Sir/Madam,
             echo
             echo "Newsletter counters =  $hitung emails"
             echo
             echo
             echo Thank You
             echo Administrator
        )    | /usr/sbin/sendmail  -t
            done
        echo -n "Email Report telah dikirim, terima kasih " ; date
   }


KIRIM ()   
   {
    ## JANGAN RUBAH BAGIAN INI, KARENA SUDAH DEFAULT ##

    for MAILTO in `cat /opt/blastmail/recipient/$PENERIMA`
    do
        export FROM="Customer Service karir.com "           
        export BODY="/opt/blastmail/body/*.html"   
        (
         echo "To: $MAILTO"
         echo "From: $FROM"
         echo "Subject: $SUBJECT"
         echo "MIME-Version: 1.0"
         echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
         echo 
         echo '---q1w2e3r4t5'
         echo "Content-Type: text/html"
         echo "Content-Disposition: inline"
         cat $BODY               
         echo
          echo '---q1w2e3r4t5--'
        ) | /usr/sbin/sendmail  -t
         GENLOG            
            done
        echo -n "Email telah dikirim, terima kasih " ;
   }


DEBUG ()
{
    for MAILTO in `cat /opt/blastmail/recipient/coba`
    do
    NOW=$(date +"%Y%m%d")
    hitung=$(cat /opt/blastmail/recipient/*.csv | sed 's/ /\n/g' | wc -l)
        export FROM="cs@karir.com"
        export SUBJECT="Newsletter Report $NOW (debug mode)"
        (
         echo "To: $MAILTO"
         echo "From: $FROM"
         echo "Subject: $SUBJECT"
     echo $hitung emails
         echo
         echo
         echo
         echo Thank You
         echo Administrator
          )| /usr/sbin/sendmail  -t
        done
        echo "Email debug report sudah dikirim, terima kasih"; date
}

kirimdebug ()
{
## JANGAN RUBAH BAGIAN INI, KARENA SUDAH DEFAULT ##

    for MAILTO in `cat /opt/blastmail/recipient/coba`
        do
    hitung2=$(cat /opt/blastmail/recipient/*.csv | sed 's/ /\n/g' | wc -l)
    export FROM="Customer Service karir.com "     # alamat email pengirim
    export BODY="/opt/blastmail/body/*.html"    # isi body email yang berupa html
        (
         echo "To: $MAILTO"
         echo "From: $FROM"
         echo "Subject: $SUBJECT (DEBUG MODE)"
         echo "MIME-Version: 1.0"
         echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
         echo 
         echo '---q1w2e3r4t5'
         echo "Content-Type: text/html"
         echo "Content-Disposition: inline"
         cat $BODY                # eksekusi body email
         echo
          echo '---q1w2e3r4t5--'
        ) | /usr/sbin/sendmail  -t
            done

    echo "Email Uji Coba Sudah Dikirim, ada $hitung2 recipient"
}

if [ $1 = "-v" ]; then
 clear ; echo "Blastmail with Shell Script Version $VER "; else
    if [ $1 = "-i" ]; then
    clear; hitung=$(cat /opt/blastmail/recipient/*.csv | sed 's/ /\n/g' | wc -l); echo jumlah penerima adalah $hitung; else
    if [ $1 = "-g" ]; then
       clear; DEBUG; else       
           if [ $1 = "-help" ]; then
          clear; cat help | more ; else
           if [ $PARAMETER = "-d" ]; then
          clear; cek_parm; kirimdebug; DEBUG; else
          if [ "$2" != " " ]; then
           clear; PENERIMA=$2; cek_parm; cek_parm2
        echo -n "Harap Bersabar, System Sedang Memproses Pengiriman Email " ; date
        KIRIM
        REPORT

fi;fi;fi;fi;fi;fi


#========# File HELP
#========#
 Created By : yudi ariestya putranto
   

1. format Penggunaan
   kirim.sh

Comments

Popular posts from this blog

Configure Open Smtp google with Postfix

membuat random password di linux

ISCSI