Help with code to move mail on receipt to another folder based on time received

Doug Horton

New Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server
I have a motion sensing security camera in my server room. It sends a mail message with a snapshot any time motion is detected. I'm trying to create a rules script that moves those messages received between the hours of 6am and 6pm to another folder (so I don't have to see them in my inbox during the day).

The following VBA code was created for this purpose:

Sub ProcessServerCamMail(Item As Outlook.MailItem)
Dim strFolder As String
Dim rectime As Date

rectime = TimeValue(Item.ReceivedTime)
strFolder = "ServerCams"

If rectime > TimeValue("6:00 am") And rectime < TimeValue("6:00 pm") Then
Item.Move Session.GetDefaultFolder(olFolderInbox).Folders(strFolder)
End If​

End Sub​

The problem I am having is that this only works if the destination folder is a subfolder under "Inbox". However, my subfolder is at the same level as Inbox. In other words, it's a subfolder of the mailbox, not Inbox.

How can I modify this to work with "ServerCams" folder at the same level as my Inbox?

We are using Exchange 2007 and Outlook 2013.

Thanks,
Doug.
 
Top