OutBox Message.

  • From: "Baiju K. Jayarajan" <Baiju.Jayarajan@xxxxxxxxx>
  • To: "[ExchangeList] (E-mail)" <exchangelist@xxxxxxxxxxxxx>
  • Date: Mon, 23 Feb 2004 09:01:39 +0300

Title: OutBox Message.

FYI

The attached is the Agents Script which im running on Exchange 2000 Server.

Firstly script check the total record count within the public folder from user-Defined-Fields in a folder.

The Function WriteToLog  - writes debug messages to log

First check the Status of the existing records,

if status is "Outstanding" then

Check the target date and validate this target date from system date

check the followupuser ID in records

After all validations create a OutBox Message

Please check the attachment and provide the correct syntax

Thanks

test.ex2@xxxxxxxxx

<<mars1.txt>>

<SCRIPT RunAt=Server Language=VBScript>

'------------------------------------------------------------------------------
'FILE DESCRIPTION: ISSUE TRACKING SYSTEM
'------------------------------------------------------------------------------

Option Explicit 

'------------------------------------------------------------------------------
' Global Variables
'------------------------------------------------------------------------------
Dim objSession
Dim objOutboxMsg
Dim fldMars
Dim oRecords
Dim oRec

const CdoTo = 1

'------------------------------------------------------------------------------
' Event Handlers
' DESCRIPTION: This event is fired when a new message is added to the folder
'------------------------------------------------------------------------------

Public Sub Folder_OnMessageCreated

Dim szSendTo
Dim szSendCc
Dim oRecipients
Dim currentdate
Dim IssueDate
Dim szDateDiff
Dim objMarsFolder
Dim szIssStatus
Dim szRecordCount
Dim szReportNo
Dim szTargetDate
Dim szDefaultDate

Dim oGAL
Dim oAddEntryColl
DimoEmail
Dim GetEmailAddr

Dim szArray
Dim szArrayYear
Dim szArrayMonth
Dim szArrayDat

Dim szReminderDateDiff
Dim szFollowupDateDiff
Dim szFirstMailFollowupTo
Dim szFirstMailFollowupCc
Dim szSecondMailFollowupTo
Dim szSecondMailFollowupCc
Dim szThirdMailFollowupTo
Dim szThirdMailFollowupCc
Dim szForthMailFollowupTo
Dim szForthMailFollowupCc
Dim i

        If Err.Number = 0 Then
                WriteToLog 0,"Script Begins........."
        Else
                WriteToLog 0,"Failed " & Err.Description
        End If

        WriteToLog 0,Folder_OnMessage Created Event Fired"

        objMarsFolder = EventDetails.FolderID

        'Clear errors
        Err.Clear
        
        'Create Event Sesssion
        Set objSession = EventDetails.Session

        If Err.Number = 0 Then
                'Get the Folder Id
                Set fldMars = objSession.GetFolder( objMarsFolder, Null )
                
                '-------------------------
                'Display the Folder ID
                '-------------------------
                WriteToLog 0,"Target Folder Id"
        else
                '-------------------------
                'Display if Error
                '-------------------------
                WriteToLog 0,"Invalid Folder Specified" 
        end if          

        'Check records

        set oRecords = fldMars.Messages

        'Check how many records has been posted to this folder

        szRecordCount = oRecords.Count

        If len(szRecordCount) > 0 Then
                '-------------------------
                'Display the record count if records found
                '-------------------------
                WriteToLog 0,"There are " & szRecordCount & " records in the 
folder."
        Else
                '-------------------------
                'Display if no records
                '-------------------------
                WriteToLog 0,"No Records Found."
        End If


        for i = 1 to oRecords.Count

                'Retrieve the records
                set oRec = oRecords.Item(i)

                '-------------------------
                'Check the Issue No
                '-------------------------
                szReportNo = oRec.Fields("FmlReportNo")

                '-------------------------
                'Display the Issue No to Log
                '-------------------------
                WriteToLog 0,"Issue No = " & szReportNo & "."

                '-------------------------
                'check the status
                '-------------------------
                szIssStatus = oRec.Fields("IssStatus")

                '-------------------------
                'Display  status to log
                '-------------------------
                WriteToLog 0,"Status = " & szIssStatus & "."

                '-------------------------
                'Check the Target date
                '-------------------------
                szTargetDate = oRec.Fields("IssCorrActionTargetDate")

                '-------------------------
                'Display  Target Date to log
                '-------------------------
                WriteToLog 0,"Target Date = " & szTargetDate & "."

                '-------------------------
                'Check System Date
                '-------------------------
                szDefaultDate = date()
                
                
                szArray = split(szDefaultDate,"/")
                szArrayYear = szArray(2)
                szArrayMonth = szArray(0)
                szArrayDat = szArray(1)

                szDefaultDate = szArray(2) &"/"& szArray(0) &"/"& szArray(1)

                '-------------------------
                'Display  Default Date to log
                '-------------------------
                WriteToLog 0,"Date = " & szDefaultDate & " "


                '----------------
                'Check the Status
                '----------------
                if Trim(szIssStatus) = "OutStanding" then

                        '-------------------------
                        'Check First Mail Follow up TO
                        '-------------------------
                        szFirstMailFollowupTo = 
oRec.Fields("IssFirstMailFollowupTO")

                        '-------------------------
                        'Display First Mail Followup To - Log
                        '-------------------------
                        WriteToLog 0,"First Mail Followup To = " & 
szFirstMailFollowupTo & ". " 

                        '-------------------------
                        'Check First Mail Follow up Cc
                        '-------------------------
                        szFirstMailFollowupCc = 
oRec.Fields("IssFirstMailFollowupCC")

                        '-------------------------
                        'Display First Mail Followup Cc - Log
                        '-------------------------
                        WriteToLog 0,"First Mail Followup CC = " & 
szFirstMailFollowupCc & ". "
        
                        '-------------------------
                        'Calculate the Date Differece for Followups
                        '-------------------------
                        szFollowupDateDiff = 
datediff("d",szDefaultDate,szTargetDate)

                        '-------------------------
                        'Display Date Difference to log
                        '-------------------------
                        WriteToLog 0,"Follow up Date Difference = " & 
szFollowupDateDiff & " ."
        
                        if szFollowupDateDiff = 10 then
                                '-------------------------
                                'Display Reminder
                                '-------------------------
                                WriteToLog 0,"First Reminder : Before 10 days 
of Expiry Date."

                        elseif szFollowupDateDiff = 5 then
                                '-------------------------
                                'Display Reminder
                                '-------------------------
                                WriteToLog 0,"Second Reminder : Before 5 days 
of Expiry Date."

                        end if

                        Set objOutboxMsg = objSession.Outbox.Messages.Add

                        Set oRecipients = objOutboxMsg.Recipients.Add

                        set szSendTo = oRec.Fields("IssFirstMailFollowupTO")
                        WriteToLog 0,"szSendTo = " & szSendTo & " "
                        set szSendCc = oRec.Fields("IssFirstMailFollowupCC")
                        WriteToLog 0,"szSendCc = " & szSendCc & " "

                        oRecipients.Name = szSendTo
                        WriteToLog 0,"oRecipients.Name = " & oRecipients.Name & 
" "

                        oRecipients.Resolve

                        If oRecipients.Name = szSendTo Then
                                Set oEmail = oRecipients.Fields(972947486) 
                                GetEmailAddr = oEmail
                        End If
        
                        objOutboxMsg.Recipients.Add "",GetEmailAddr,CdoTo,""
                        objOutboxMsg.Send

                else
                        WriteToLog 0,"Balaji : Status is not outstanding for " 
& szReportNo & " "
                end if
        next
                WriteToLog 0,"Folder_OnMessageCreated Event Ended"
End Sub

'------------------------------------------------------------------------------
' Event Handlers
' DESCRIPTION: This event is fired when a message in the folder is changed
'------------------------------------------------------------------------------

Public Sub Message_OnChange
WriteToLog 0,"Balaji : Message_OnChange Event"
End Sub

'------------------------------------------------------------------------------
' Event Handlers
' DESCRIPTION: This event is fired when a message is deleted from the folder
'------------------------------------------------------------------------------

Public Sub Folder_OnMessageDeleted
End Sub

'------------------------------------------------------------------------------
' Event Handlers
' DESCRIPTION: This event is fired when the timer on the folder expires
'------------------------------------------------------------------------------

Public Sub Folder_OnTimer

End Sub

'--------------------------------------
' Supported Functions
' DESCRIPTION: This event writes to log
'--------------------------------------

Private Sub WriteToLog(boolRecordName,strMessage)
        Dim strResponse
        strResponse = Now & vbTab & strMessage & " "
        if boolRecordName = 0 then
                strResponse = strResponse & " "
        end if
        Script.Response = Script.Response & vbNewLine & strResponse
end Sub 

</SCRIPT>

Other related posts:

  • » OutBox Message.