Blastmail with shell script version 3.0

* JUDUL       : BLASTMAIL Versi.3.0     
* created by   : YUDI ARIESTYA PUTRANTO                                       
* email           : yudi.ariestya@live.com                                                       
* lastcreate     : 2 April 2013                                                                
* Version        : 3.0                                                                                       

====================================================================
*** 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. saya sengaja tidak share update versi 2.0, karena gak sempat update hehehehe
6. yang baru liat blog ini, coba pelajari dulu ya dari blastmail versi 1.0 
7.  tambahkan  di belakang script  > /dev/null 2>&1 &  untuk menjalankan perintah tersebut di background


====================================================================

dalam versi 3.0 ini saya lakukan beberapa penyempurnaan untuk aplikasi blastmail ini, antara lain adalah
1.  penggunaan aplikasi kirim.sh yang sebelumnya menggunakan popup question (versi 2.x), sekarang dijadikan parameter, fungsinya adalah memudahkan penggunaan aplikasi jika ingin menjalankannya dengan menggunakan crontab
2. peringkasan penulisan shell script, yang sebelumnya aplikasi kirim.sh membutuhkan file pendukung seperti genlog.sh dan report.sh. pada update versi 3.0 ini file tersebut dijadikan fungtion yang di tempatkan didalam body kirim.sh
3. peringkasan penulisan shell script pada aplikasi kirimdebug.sh, dimana sebelumnya aplikasi ini mebutuhkan file lain seperti, debug.sh. pada versi ini shell script code yang ada di file debug.sh dijadikan function didalam kirimdebug.sh
4. saya tambahkan tools shell script code untuk menghitung jumlah email terkirim .
5. penambahan penggunaan rotate.sh (lihat rotate.sh)

A. kirim.sh

#!/bin/bash
##=================================================================##
## file ini berisi perintah untuk mengirimkan email            

## imput : Subject , file csv                                                                      
## PENTING = cek kembali imputan dan konversi le lowercase         
## Created By   : Yudi Ariestya Putranto                           
## email        : yudi.ariestya@live.com                           
## Version    : 3.0                          
## Lihat Readme untuk penggunaan lengkap nya              
##=================================================================##

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

# make sure file exits for reading
        if [ ! -f /opt/blastmail/body/*.html ]; then
        echo "File html tidak ada"
        exit 1
        fi
        if [ ! -f /opt/blastmail/recipient/"${PENERIMA,,}" ]; then
          echo "Filename "${PENERIMA,,}" does not exists"
          exit 1
        else
          echo "Harap Bersabar, System Sedang Memproses $hitung Pengiriman Email"
        fi

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

   }

    REPORT ()
    {
    for MAILTO in `cat /opt/blastmail/recipient/debug`
    do
        NOW=$(date +"%Y%m%d")
        SUBJECT=$( cat subject | grep $NOW |awk -F "," '{print $1}'| sed -e "s/ //g" )
        hitung=$(cat /opt/blastmail/log/subject.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 How Days,
             echo
             echo "Newsletter counters =  $hitung emails"
             echo
             echo
             echo Thank You
             echo Administrator
        )    | /usr/sbin/sendmail  -t
            done
        echo "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--'
         GENLOG            
        ) | /usr/sbin/sendmail  -t
            done
        echo "Email telah dikirim, terima kasih"; date
    }
## BATAS AKHIR BARIS YANG TIDAK BOLEH DI EDIT ##

# ini perintah sebenarnya
if [ $PARAMETER -ge 1 ]
then
    KIRIM
    REPORT
else
    echo "Mengirim tanpa summary report"
    KIRIM
fi

#remove template
mv /opt/blastmail/body/*.html /opt/blastmail/senditems/newsletter-body.html # pindahkan file html ke /event setelah pengiriman
mv /opt/blastmail/recipient/*.csv /opt/blastmail/senditems/newsletter-recipient.csv
cd /opt/blastmail/senditems/; ./rotate.sh 7 newsletter-body.html newsletter-recipient.csv


======================================================================
B. kirimdebug.sh
#!/bin/bash
##=================================================================##
## file ini berisi perintah untuk mengirimkan email           
## input : Subject , file csv                       
## PENTING = cek kembali imputan dan konversi le lowercase        
## Created By   : Yudi Ariestya Putranto                          
## email        : yudi.ariestya@live.com                          
## Version    : 3.0                          
##=================================================================##

NOW=$(date +"%Y%m%d")
SUBJECT=$1
echo $SUBJECT > /opt/blastmail/subject
RECIPIENT=$2
echo $RECIPIENT > /opt/blastmail/penerima
DEBUG ()
{
    for MAILTO in `cat /opt/blastmail/recipient/$RECIPIENT`
    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 Dear Sir/Madam,
         echo How Days,
     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/$RECIPIENT`
        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 [ ! -f /opt/blastmail/body/*.html ]
    then
    echo "File materi newsleter (*.html) tidak ada"
    exit 0
    else
        if [ ! -f /opt/blastmail/recipient/*.csv ]
        then
        kirimdebug
        else
        kirimdebug
        DEBUG
fi
        fi
## BATAS AKHIR BARIS YANG TIDAK BOLEH DI EDIT ##

Comments

Popular posts from this blog

Configure Open Smtp google with Postfix

membuat random password di linux

ISCSI