
4,381 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Code:
Imports Microsoft.Office.Interop.Outlook
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim oApp As New Application
Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim RootFolder As MAPIFolder = oNS.DefaultStore.GetRootFolder
For Each MFolder As Microsoft.Office.Interop.Outlook.Folder In RootFolder.Folders
Try
If MFolder.DefaultItemType = OlItemType.olMailItem Then
Dim MBItems As Items = MFolder.Items
For Each EMailitem As MailItem In MBItems
Dim Atchmnts As Attachments = EMailitem.Attachments
If Atchmnts.Count > 0 Then
TextBox1.AppendText("Folder: " & MFolder.Name & vbNewLine)
TextBox1.AppendText("From: " & EMailitem.SenderName & vbNewLine)
TextBox1.AppendText("Subj: " & EMailitem.Subject & vbNewLine)
TextBox1.AppendText(Atchmnts.Count.ToString & " Attachment(s):" & vbNewLine)
For Each a As Microsoft.Office.Interop.Outlook.Attachment In Atchmnts
TextBox1.AppendText(vbTab & a.FileName & " - " & a.Size.ToString & " bytes" & vbNewLine)
Next
TextBox1.AppendText(vbNewLine)
End If
Next
End If
Catch
TextBox1.AppendText("Error Processing " & vbNewLine)
End Try
Next
TextBox1.AppendText("Finished")
oApp.Quit()
oApp = Nothing
oNS = Nothing
End Sub
End Class
One result:
Folder: Inbox
From: Maria xxxxxxxxxxxxx
Subj: RE: Sewer Drawing
3 Attachment(s):
image001.png - 6561 bytes (embedded logo, not a real attachment)
image002
38883.tif - 1052020 bytes (actual attached file)