PDA

View Full Version : Capture emails which are moved



DawnTreader
04-24-2015, 01:42 PM
Hello All

I found a thread from a while back that dealt with this but I need to get some help with the code I found there. here is my scenario:

I would like to run this against the mainstore of my outlook account so that anytime an email from the inbox is moved to any other mail folder it will be tagged with a date. this code looks like it would do the job, but I have more than 2 folders that I want to "watch". in fact I need to watch any folder that holds mail items, especially if a new folder is created.

Another problem is the fact that these emails might not be moved within the current open outlook session on my computer but might be moved by someone else who has been given full access through exchange server. the situation is that we have a "pool" address that receives all of our service email and is delegated to various people. when someone is given the task it moves to a "My_tasks\persons name" folder. when they complete it they move it to a "completed\country" folder.

I was thinking that if I put the "watch" on the mainstore that might work, I haven't tried it yet, I thought I would get this post in so that I could get feedback on the idea asap as I am on a time crunch with the code.

here is the code I had found:


Private WithEvents Items1 As Outlook.Items
Private WithEvents Items2 As Outlook.Items

Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' change these lines to point to the subfolders you are moving emails to
Set Items1 = objNS.GetDefaultFolder(olFolderInbox).Folders("SubFolder 1").Items
Set Items2 = objNS.GetDefaultFolder(olFolderInbox).Folders("SubFolder 2").Items
End Sub

Private Sub Items1_ItemAdd(ByVal item As Object)

On Error Goto ErrorHandler

Dim Msg As Outlook.MailItem

If TypeName(item) = "MailItem" Then
Set Msg = item
' change this to do what you want with the information, i.e. generate a new email, write info to spreadsheet, etc
Debug.Print Msg.ReceivedTime & " " & Msg.SenderName & " " & Msg.Subject & " " & Format(Now, "mm/dd/yyyy") & " " & Items1.Parent.Name

End If

ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub

Private Sub Items2_ItemAdd(ByVal item As Object)

On Error Goto ErrorHandler

Dim Msg As Outlook.MailItem

If TypeName(item) = "MailItem" Then
Set Msg = item
' change this to do what you want with the information, i.e. generate a new email, write info to spreadsheet, etc
Debug.Print Msg.ReceivedTime & " " & Msg.SenderName & " " & Msg.Subject & " " & Format(Now, "mm/dd/yyyy") & " " & Items2.Parent.Name

End If

ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub



any and all help is appreciated.

skatonni
04-24-2015, 02:09 PM
The itemAdd event "Occurs when one or more items are added to the specified collection."

https://msdn.microsoft.com/en-us/library/office/ff869609.aspx

You will have to monitor all "My_tasks\persons name" folders.

Should work when others move items if you leave your Outlook on all the time.

DawnTreader
04-24-2015, 03:01 PM
So is there a way to monitor all folders rather than the items?

DawnTreader
05-01-2015, 01:54 PM
Hello All

Here is the scenario:

We have a service department that has 4 Customer Service Representatives and many Technicians that they manage. All of the Parts and Service requests come in by email to one central email "pool". This pool has a few rules on it that are run 24 hours a day by having a dedicated computer logged in as the "pool" account. So there is always an outlook client logged in as customerservice at mycompany dot com so that the rules on needed on that account will always be running. Each of the CSR's have access to the same inbox through their logins and they deal with the emails are assigned to them by a manager. The manager assigns the emails by moving the email from the inbox to a "my_tasks \ CSR Name folder". After a CSR finishes dealing with it, they move it again to a "Completed \ Category" folder.

I need to be able to report on how long it takes each email to be "completed" and how many are coming in to the main inbox and flowing through each "my_tasks \ CSR Name folder". It seems to me that I need to capture when each email comes in, the first move to assign it and the second move to show it completed. The first capture is easy as I have a rule running on incoming email that runs VBA code to insert a record into an Access database and then bring back the records PrimaryKeyID and insert it into a user field called EmailID. I also have code that I can run from an Access frontend database that imports and updates emails to match the current state of each email in the inbox. This definitely captures the completed state, but I am not sure if it is capturing the assigned and when that happened.

I was thinking that maybe I need a "manager addin" for the outlook used by the manager that "assigns" the email and moves it with a date tag. But if I can capture moves from the single client then I can manage this without an add in.

So instead of asking the original question of how to capture emails are moved, here is the questions I think I should really be asking:

I need to know if I can run the above code on the 24 hours logged in outlook client and have it catch all the moves or if the moves need to be captured on each computer that are managing the emails from the "pool"? Has anyone ever had to work with this sort of a system?

After knowing if that is possible I will then have to figure out how to monitor all folders and perform the actions necessary.

Any and all insights, help, code and suggestions are greatly appreciated.