Well, first you need to download and install
Redistributable Primary Interop Assemblies for the MS Office version you are using.
Then you should add a reference to the outlook interop assembly.
Then try this code. It's been ported from VB6 so there might be some inconsitencies.
vb.net Code:
Public Sub ProcessInbox() Dim oOutlook As Outlook.Application Dim oNs As Outlook.NameSpace Dim oFldr As Outlook.MAPIFolder Dim oAttachments As Outlook.Attachments Dim oAttachment As Outlook.Attachment Dim iMsgCount As Integer Dim oMessage As Outlook.MailItem Dim iCtr As Long, iAttachCnt As Long Dim sFileNames As String Dim aFileNames() As String 'get reference to inbox oOutlook = New Outlook.Application oNs = oOutlook.GetNamespace("MAPI") oFldr = oNs.GetDefaultFolder(olFolderInbox) Debug.WriteLine ("Total Items: " & oFldr.Items.Count) Debug.WriteLine("Total Unread items = " & oFldr.UnReadItemCount) For Each oMessage In oFldr.Items With oMessage 'basic info about message Debug.WriteLine(.To) Debug.WriteLine(.CC) Debug.WriteLine(.Subject) Debug.WriteLine(.Body) If .UnRead Then Debug.WriteLine("Message has not been read") Else Debug.WriteLine("Message has been read") End If iMsgCount = iMsgCount + 1 'reference and save all attachments With oMessage.Attachments iAttachCnt = .Count If iAttachCnt > 0 Then For iCtr = 1 To iAttachCnt .Item(iCtr).SaveAsFile "C:\" & .Item(iCtr).FileName Next iCtr End If End With End With Application.DoEvents Next oMessage End Sub




Reply With Quote
