2010-04-09 45 views
0

我正在使用vb.net從Outlook Express中顯示電子郵件!一切工作正常,但當一些消息有附件,我不能顯示該電子郵件有附件的消息!檢查郵件附件

這是我的代碼:

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 

如何顯示消息的電子郵件附件有?

+0

看起來你已經在這裏粘貼了3組代碼? – 76mel 2010-04-11 19:35:48

回答

1

爲什麼不使用Message.Attachments.Count?