I am using this below code to pull the details from outlook inbox into vb.net list view. Somehow, the data is not populating properly (see attached image). Also, I am not able to see headers for the list view. Can someone help me on this.
Dim oApp As Outlook.Application = New Outlook.Application
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
' Get Messages collection of Inbox.
Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Outlook.Items = oInbox.Items
oItems = oItems '.Restrict("[Unread] = true")
' Console.WriteLine("Total Unread : " & oItems.Count) ' Get unread e-mail messages.
Dim oMsg As Outlook.MailItem
Dim i As Integer
For i = 1 To oItems.Count
'Test to make sure item is a mail item and not a meeting request.
If oItems.Item(i).MessageClass = "IPM.Note" Then
oMsg = oItems.Item(i)
Dim msgStr(3) As String
msgStr(0) = oMsg.ReceivedTime
msgStr(1) = oMsg.SenderName
msgStr(2) = oMsg.Subject
Dim lstViewItem As New ListViewItem(msgStr)
'lstViewItem.Tag = oMsg.Body
ListView2.Items.Add(lstViewItem)
End If
Next
oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing
To see columns and column headers you need to set the View
property of the ListView
to Details
and create columns, for instance like this:
With Me.ListViewMails
.Columns.Add("ReceivedTime", 100)
.Columns.Add("Sender", 100)
.Columns.Add("Subject", 300)
End With
To put your mail info inside the separate columns you can do something like this:
Dim item As ListViewItem
item = Me.ListViewMails.Items.Add("2018-01-07") 'main column, usually the first one
item.SubItems.Add("John Doe") 'second column
item.SubItems.Add("This is my very own subject") 'third column
You need to play around with the several overloads of the Add
functions to get what you want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.