Need to programmatically read the name of an Outlook Mail Attachment in VB or VBA
Posted on 2014-01-17
I need to read a mail item attachment without first saving it to disk.
The code I am using is below. This code will cycle through all the messages in my inbox and display the subject and body in the immediate window. It will also allow me to cycle through the attachments and display the name of the attachments.
The problem is when a message bounces, the name handler attaches the original message to a new message as an attachment, and sends me the new message.
In order to programmatically determine what to do with the bounced message, I need to be able to read the body, or at least be able to read the subject.
In Outlook, if I click on the attachment it allows me to preview the message, so I'm sure this should be possible.
My code is below: This code will cycle through your inbox and display various info about each message in the immediate window.
I am using Outlook 2K
Dim oM As MailItem
Dim oF As MAPIFolder
Dim olNS As outlook.NameSpace
Dim nn As Long
Dim NumberOfAttachments As Long
Dim pp As Long
Set olNS = Application.GetNamespace("MAPI")
Set oF = olNS.GetDefaultFolder(olFolderInbox)
For nn = oF.Items.Count To 1 Step -1
Set oM = oF.Items(nn)
NumberOfAttachments = oM.Attachments.Count
If NumberOfAttachments > 0 Then
For pp = 1 To NumberOfAttachments