Are you sure the item or items in question are MailItem objects?
Using Redemption I'd probably use RDOMail objects and RDOFolder to get the
Inbox from the RDOSession object, that way I'd avoid problems like that.
Then I could check the Class or MessageClass of the RDOMail object before
working with it.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"Damian" wrote in message
oups.com...
Hi,
I am looking for some help here. I am trying to read email from an
inbox. The emails are bouncebacks. I want to be able to parse the
message body to get email addesses etc.
Problem is it hangs on the first line -- oMsg = CType(oItems.Item(i),
Outlook.MailItem)
after it goes through one loop
Below is the code I am using.
Option Strict On
Imports System.ServiceProcess
Imports MAPI
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports System.Runtime.InteropServices.Marshal
Imports System.Reflection
Imports Redemption
Dim BodyStr As String
Dim oApp As Outlook.Application = New Outlook.Application
Dim i As Integer
' Get Mapi NameSpace.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("outlook_profile", "password", False)
' Get Messages collection of Inbox.
Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderInbox)
Dim oItems As Outlook.Items = oInbox.Items
' Loop each unread message.
Dim oMsg As Outlook.MailItem
Dim oSafeMsg As Redemption.SafeMailItem
For i = 1 To oItems.Count
oMsg = CType(oItems.Item(i), Outlook.MailItem) ' hangs on
this line after the first loop
oSafeMsg = New Redemption.SafeMailItem
oSafeMsg.Item = oMsg
BodyStr = oSafeMsg.Body
' parse code goes here
ReleaseComObject(oMsg)
oMsg = Nothing
Next
' Log off.
oNS.Logoff()
' Clean up.
ReleaseComObject(oApp)
oApp = Nothing
ReleaseComObject(oNS)
oNS = Nothing
ReleaseComObject(oItems)
oItems = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
Any ideas ? Any help would be appreciated
Thanks
Damian