How to get Explorer & Inspector selected mail item using Outlook Object Model (OOM) & .Net?
In this article, we are going to see how we can get Explorer & Inspector selected mail item using Outlook Object Model (OOM) & .Net and process it.
'[Code Snippet : VB.Net, .Net Framework 2.0/3.5, Outlook Object Model (OOM)]
...
'Declaration part
Dim ThisOutlookSession As Outlook.Application = New Outlook.Application
Dim NS As Outlook.NameSpace = ThisOutlookSession.Session
Dim objsel As Object
'Check it's Inspector or Explorer Window
If TypeName(ThisOutlookSession.ActiveWindow) = "Inspector" Then
MsgBox("Inspector")
objsel = ThisOutlookSession.ActiveInspector.CurrentItem
MsgBox(objsel.Subject)
Else
MsgBox("Explorer")
'Get the selected item for processing
objsel = ThisOutlookSession.ActiveExplorer.Selection.Item(1)
'Check the relevant item and process per your logic
If (TypeOf objsel Is Outlook.MailItem) Then
Dim mailItem As Outlook.MailItem = _
TryCast(objsel, Outlook.MailItem)
MsgBox("Mail Item's Subject" & mailItem.Subject)
'Implement your business logic here
...
ElseIf (TypeOf objsel Is Outlook.ContactItem) Then
Dim contactItem As Outlook.ContactItem = _
TryCast(objsel, Outlook.ContactItem)
MsgBox("Contact Item's Subject" & contactItem.Subject)
'Implement your business logic here
...
ElseIf (TypeOf objsel Is Outlook. _
AppointmentItem) Then
Dim apptItem As Outlook.AppointmentItem = _
TryCast(objsel, Outlook.AppointmentItem)
MsgBox("Appointment Item's Subject" & apptItem.Subject)
'Implement your business logic here
...
ElseIf (TypeOf objsel Is Outlook.TaskItem) Then
Dim taskItem As Outlook.TaskItem = _
TryCast(objsel, Outlook.TaskItem)
MsgBox("Task Item's Body" & taskItem.Body)
'Implement your business logic here
...
ElseIf (TypeOf objsel Is Outlook.MeetingItem) Then
Dim meetingItem As Outlook.MeetingItem = _
TryCast(objsel, Outlook.MeetingItem)
MsgBox("Meeting Item's subject" & meetingItem.Subject)
'Implement your business logic here
...
End If
End If
'Release the unwanted objects
objsel = Nothing
...
Applicable environment: Outlook 2007, Outlook Object Model, VB.Net, .Net Framework 2.0/3.5
Comments
- Anonymous
February 17, 2009
PingBack from http://www.anith.com/?p=10825