emcee303
02-12-2006, 05:03 PM
Hi there. I'm definitely not a coder, but I've been working with one of our developers to get some alerting via our monitoring software. At the moment we are using Outlook rules to distribute the alerts, this works well but has its limitations, eg we cannot alert based on time received. To get around that problem we came up with the script below. The problem is that this will not fire as the incoming message is re-routed before hitting the inbox. How can i add this script as a macro to fire before all other rules?
Thanks for any help
Mike.
Public WithEvents myOlItems As Outlook.Items
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
On Error GoTo Error_Trap
' If it's currently not between 7:00 A.M. and 6:00 P.M.
If Time() < #7:00:00 AM# Or Time() > #6:00:00 PM# Then
' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then
' Forward the item just received
Set myForward = Item.Forward
' Address the message
myForward.Body = StripHeader(myForward.Body)
myForward.Recipients.Add "[sms:MobileNumber]"
' Send it
myForward.Send
End If
End If
Exit Sub
Error_Trap:
' Do nothing
End Sub
Public Function StripHeader(ByVal Body As String) As String
On Error GoTo Error_Trap
' Tweak interations with this constant
Const C_RETURNS As Integer = 7
Dim I As Integer
Dim intPosition As Integer
I = 0
For intPosition = 1 To Len(Body)
If I = C_RETURNS Then Exit For
If Asc(Mid(Body, intPosition, 1)) = 10 Then I = I + 1
Next
StripHeader = Mid(Body, intPosition)
Exit_Point:
Exit Function
Error_Trap:
' Return original message if an error is encountered
StripHeader = Body
End Function
Thanks for any help
Mike.
Public WithEvents myOlItems As Outlook.Items
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
On Error GoTo Error_Trap
' If it's currently not between 7:00 A.M. and 6:00 P.M.
If Time() < #7:00:00 AM# Or Time() > #6:00:00 PM# Then
' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then
' Forward the item just received
Set myForward = Item.Forward
' Address the message
myForward.Body = StripHeader(myForward.Body)
myForward.Recipients.Add "[sms:MobileNumber]"
' Send it
myForward.Send
End If
End If
Exit Sub
Error_Trap:
' Do nothing
End Sub
Public Function StripHeader(ByVal Body As String) As String
On Error GoTo Error_Trap
' Tweak interations with this constant
Const C_RETURNS As Integer = 7
Dim I As Integer
Dim intPosition As Integer
I = 0
For intPosition = 1 To Len(Body)
If I = C_RETURNS Then Exit For
If Asc(Mid(Body, intPosition, 1)) = 10 Then I = I + 1
Next
StripHeader = Mid(Body, intPosition)
Exit_Point:
Exit Function
Error_Trap:
' Return original message if an error is encountered
StripHeader = Body
End Function