Discussion:
Detect email has been read
(too old to reply)
Russ Green
2009-01-16 19:10:04 UTC
Permalink
I have an outlook 2007 adding and I want to detect when an email in my inbox
has been read, Once read I want to trigger a dialog to assist in filing the
message and attachments.

At the moment I am watching for when a mailitem in the inbox has changed and
checking it is unread which almost does the job expect the event fires more
often that I would like. Whats the best method of dealing with this?

Private Sub InboxItemsItemChange(ByVal changedItem As Object)
If TypeOf changedItem Is Outlook.MailItem Then
If DirectCast(changedItem, Outlook.MailItem).UnRead = False Then
Dim frmMain As New frmMain(New Outlook.Application,
changedItem)
frmMain.ShowDialog()
frmMain.Dispose()
End If
End If
End Sub


TIA

Russ Green
Ken Slovak - [MVP - Outlook]
2009-01-16 20:39:49 UTC
Permalink
You would have to handle each item in Explorer.Selection and also handle
Explorer.SelectionChange to know when the selection changed. For each item
you handle you would handle the Read event. You might also need to handle
the Inspectors.NewInspector event to handle when an item is opened, since it
can be opened by right-clicking on it without changing Explorer.Selection.

That will also cover items read from the reading/preview pane.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Russ Green
I have an outlook 2007 adding and I want to detect when an email in my
inbox has been read, Once read I want to trigger a dialog to assist in
filing the message and attachments.
At the moment I am watching for when a mailitem in the inbox has changed
and checking it is unread which almost does the job expect the event fires
more often that I would like. Whats the best method of dealing with this?
Private Sub InboxItemsItemChange(ByVal changedItem As Object)
If TypeOf changedItem Is Outlook.MailItem Then
If DirectCast(changedItem, Outlook.MailItem).UnRead = False Then
Dim frmMain As New frmMain(New Outlook.Application,
changedItem)
frmMain.ShowDialog()
frmMain.Dispose()
End If
End If
End Sub
TIA
Russ Green
Russ Green
2009-01-17 12:43:36 UTC
Permalink
Thanks for the pointer....did this....don't know if it's correct or good
practice but it works.

Friend Sub New(ByVal app As ThisAddin)
m_app = app

m_Exp = app.Application.ActiveExplorer
AddHandler m_Exp.SelectionChange, AddressOf ExplorerSelectionChange

#######

Private Sub ExplorerSelectionChange()
Dim exp As Outlook.Explorer = m_app.Application.ActiveExplorer
Dim selectedFolder As Outlook.MAPIFolder = Exp.CurrentFolder

Select Case selectedFolder.Name.ToLower
Case "inbox"
Try
If exp.Selection.Count > 0 Then
Dim selObject As Object = exp.Selection.Item(1)
If (TypeOf selObject Is Outlook.MailItem) Then
Dim mailItem As Outlook.MailItem =
TryCast(selObject, Outlook.MailItem)
If mailItem.UnRead = True Then
mailItem.Display(True)
Dim frm As New frmMain(New
Outlook.Application, mailItem)
With frm
.ShowDialog()
.Dispose()
End With
End If
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try

Case "sent items"

End Select
End Sub

Loading...