I'm following the samples shown on MSDN but I'm missing a part because I can't get an "event" to be triggered.
The goal is to append the timestamp and username at the end of the message each time a user opens/preview/mark as read a mail item.
I've read MailItem.Open (https://msdn.microsoft.com/en-us/library/office/ff865989.aspx) and MailItem.Read (https://msdn.microsoft.com/EN-US/library/office/ff869872.aspx). I've disabled macro security (Enable All macros).
My code in "ThisOutlookSession". I'm restarting Outlook each time I change something:
Public WithEvents SelectedItem As Outlook.MailItem
Sub Initialize_handler()
Set SelectedItem = Application.ActiveExplorer.CurrentFolder.Items(1)
SelectedItem.Display
End Sub
Sub SelectedItem_Read()
MsgBox "Trigger by MailItem.Read"
End Sub
Sub SelectedItem_Open()
MsgBox "Trigger by MailItem.Open"
End Sub
I can't get the msgbox to display in any cases of open/preview for 3 seconds/mark as read by the user.
When the events work, I plan to call the following sub:
Sub MessageWasOpenned()
Dim myItem As MailItem
Set SelectedItems = ActiveExplorer.Selection
For Each myItem In SelectedItems
myItem.Body = myItem.Body & vbCrLf & "This message was opened by: " & (Environ$("Username")) & " on: " & Now
myItem.Save
Next
End Sub