Hi!
I am using vb.net to display email from outlook express! Everything work fine but when some message has attachment, i can not display message that email has attachment!
This is my code:
Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginButton.Click
Dim oItem
Dim i As Integer
Dim Message As MAPI.Message
Dim items As String() = New String(6) {} ' Items are the sender name,subject and date and read/unread value
Dim PrSenderEmail, PrBodyEmail
Session = CreateObject("MAPI.Session") ' we use a session object of MAPI Component
Session.Logon(ProfileName:=Me.UserId.Text, ProfilePassword:=Me.Password.Text)
Session.MAPIOBJECT = Session.MAPIOBJECT '
Folder = CObj(Session.Inbox) ' choose the folder
Application = CreateObject("Outlook.Application")
Namespace1 = Application.GetNamespace("MAPI")
Namespace1.Logon()
' for getting the sender name and avoid security validation of Outlook/Exchange server 2003
' we are using the "Redemption" component
sItem = CreateObject("Redemption.SafeMailItem")
Cursor.Current = Cursors.WaitCursor ' show we're busy doing the sort
ListInbox.BeginUpdate() ' Notify that update begins
ListInbox.Items.Clear()
i = 0 ' first email message is 0
For Each Message In Folder.Messages
Try
i = i + 1 ' increment to the next email message
'get e-mail from the Inbox, can be any other item
oItem = Application.Session.GetDefaultFolder(6).Items(i) ' GetDefaultFolder(6) refers to Inbox
sItem.Item = oItem
'sItem is an object of Redemption COM and is used to get the senders name
items(0) = sItem.SenderName()
Catch
items(0) = "error"
End Try
Dim objApp As Outlook.Application = New Outlook.Application
'Get Mapi NameSpace
Dim objNS As Outlook.NameSpace = objApp.GetNamespace("MAPI")
Dim oMsg As Outlook.MailItem
Dim pp As String
Dim b As Integer
Dim objAttachment As Outlook.Attachment
pp = Message.StoreID
items(1) = Message.Subject
items(2) = Message.TimeReceived
items(4) = Message.Subject
items(5) = Message.Size
Dim objInbox As Outlook.MAPIFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim objItems As Outlook.Items = objInbox.Items
items(5) = Message.Size.ToString / 1000 & "kb"
If Message.Unread = True Then
items(3) = "unread"
Else
items(3) = "read"
End If
ListInbox.Items.Add(New ListViewItem(items))
Next
ListInbox.EndUpdate() ' Notify that update ends
Cursor.Current = Cursors.Default
End If
End Sub
How I can display message that email has attachment?