I've posted in the Office Forum thread68-731432, but not sure which forum would help most.
I am able to pull back emails in my Outlook Inbox with the following code, however, if the email has no subject line, I get an invalid cast exception. Can anyone take a look at the code below and help me get through this? Thanks
regards,
Brian
I am able to pull back emails in my Outlook Inbox with the following code, however, if the email has no subject line, I get an invalid cast exception. Can anyone take a look at the code below and help me get through this? Thanks
Code:
Dim olApp As Outlook.Application = New Outlook.Application()
Dim olNS As Outlook.NameSpace = olApp.GetNamespace("MAPI")
olNS.Logon("Brian Gaines", "", False, True)
Dim olInbox As Outlook.MAPIFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim olItems As Outlook.Items = olInbox.Items
Dim i As Integer
Try
If olItems.Count > 0 Then
ListBox1.Items.Clear()
For i = 1 To olItems.Count
Dim email As Outlook.MailItem = olItems.Item(i)
ListBox1.Items.Add(email.Subject & " >>> FROM: " & email.SenderName)
Next
Label1.Text = "Emails: " & (i - 1).ToString
olNS.Logoff()
End If
Catch ex As Exception
lblMessage.Text = ex.ToString
Finally
olApp = Nothing
olNS = Nothing
olItems = Nothing
olInbox = Nothing
End Try
regards,
Brian