Sending Mail on GNU/ Linux Server [HOW TO]

Judul nya pake bahasa inggris, dan sifatnya (lagi-lagi) teknis, bosen banget ya.. moga-moga dapet hal yg sifatnya lebih ke Manajemen. Aamiin.. InsyAllah kedepannya.

Langkah Instant-Nya:
Dengan (seharusnya) tetap memperhatikan SASL, STARTTLS (advanced protocol plain text) atau TLS dll (port 25 change to 465 etc)

telnet mail.<domain_corporate>.com 25
ehlo mail.<domain_corporate>.com
mail from: <src_mail>
rcpt to: <dest_mail>
data
Subject :
<isian>
.

yum install php-pear
pear install Mail
pear install Mail_Mime
pear install Net_SMTP

Kemudian, gunakan 2 script shell dan php berikut (daftarkan di cronjob).
#!/bin/bash

ago=`date -d “1 days ago” +”%Y%m%d”`
ago2=`date -d “1 days ago” +”%Y-%m-%d”`

echo “Status  : Jumlah    ” >> /home/hary/logs/WapDRInst_$ago2.txt
for i in $(cat /home/hary/stat);
do
        stat=`echo $i`;
        sum=`bzgrep blabla /app/operator/mcp/logs/access_log-$ago.bz2 | awk -F ‘&status=’ ‘{print $2}’ | awk -F ‘&instid=’ ‘{print $1}’ | grep “$stat” | wc -l`
        #echo $sum;
        echo “$stat     :       $sum” >> /home/hary/logs/WapDRInst_$ago2.txt
done
sed -i ‘s/\\//’ /home/hary/logs/WapDRInst_2015-04-15.txt

Ini code PHP nya:
<?php
/*
*
* Hey you Hary
*
*/

require_once(“/usr/share/pear/Mail.php”);
require_once(“/usr/share/pear/Mail/mime.php”);

$time = date(“Y-m-d”, strtotime(“previous day”));
$subject = “[BLABLA] Cicilan Report [YATTA]”;
$url = “/home/hary/logs/WapDRInst_$time.txt”;
$content = file_get_contents($url);

/**
Complement
**/
$body   = “Dear All, <br><br>
        Below Reporting Blabla : <br>”;
$body   .= “<table border=1 bordercolor=green bgcolor=white cellpadding=0 cellspacing=0>”;
$body   .= “
        <tr>
        <td rowspan=4>
                Wakimobi
        </td>
        <td align=center valign=middle width=100px colspan=4><b>Blabla report</b></td>
        <td>
                <tr bgcolor=’white’><font color=’black’>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>CP Name</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Yattaera Solution</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>Date</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>$time</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>Prepared By</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Waki Messaging Team</font></td>
                </tr>
        </td>
        </tr>
        </table>”;

/**
Testing
**/
$body   .= “<table border=1 bordercolor=green bgcolor=white>”;
$body   .= “<br><pre> $content</pre>”;
$body   .= “</table>”;

$body   .= “<table border=1 bordercolor=green bgcolor=white cellpadding=0 cellspacing=0>”;
$body   .= “
                <tr bgcolor=’white’><font color=’black’>
                        <td align=’center’ bgcolor=’grey’><font color=’black’ face=’Tahoma’ size=2>Status</font></td>
                        <td align=’center’ bgcolor=’grey’><font color=’black’ face ‘Tahoma’ size=2>Description</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>0</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Success</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-1</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Invalid/Incomplete Parameter</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-2</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Invalid Service Code</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-3</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Invalid Charging Code</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-4</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Invalid MSISDN</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-5</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Invalid Network</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-6</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Insufficient Balance</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-7</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Invalid Request ID, already used</font></td>
                </tr>
                <tr>

<td align=’center’><font color=’black’ face=’Tahoma’ size=2>-8</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, User Abort / Cancel during confirmation</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-9</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Invalid Installment</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-10</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Error, Charging Failed</font></td>
                </tr>
                <tr>
                        <td align=’center’><font color=’black’ face=’Tahoma’ size=2>-99</font></td>
                        <td align=’left’><font color=’black’ face ‘Tahoma’ size=2>Internal Error</font></td>
                </tr>
        </table>”;

$to    = array(“<destination_mail>”);
$crlf   = “\n”;
$mime   = new Mail_mime($crlf);
$from   = “<src_mail>”;
$host   = “mail.<domain_corporate>.com”;
$port   = “25”;

$username       = “”;
$password       = “”;

$headers        = array(‘From’ => $from, ‘To’ => $to, ‘Subject’ => $subject);
$smtp           = Mail::factory(‘smtp’, array(‘host’ => $host, ‘port’ => $port, ‘auth’ => false, ‘username’ => $username, ‘password’ => $password));
$mime->setHTMLBody($body);
$newbody        = $mime->get();
$headers        = $mime->headers($headers);
$mail           = $smtp->send($to, $headers, $newbody);

if (PEAR::isError($mail)){
        echo(“<p> Email Gagal Kirim”.$mail->getMessage().”</p>”);
}
else{
        echo “Email berhasil dikirim”;
}

 

Makasih.

Advertisements

Tinggalkan pesan atau komentar

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s