pcalabria
asked on
Need to programmatically read the name of an Outlook Mail Attachment in VB or VBA
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
Sub TestMail()
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(olFo lderInbox)
For nn = oF.Items.Count To 1 Step -1
Set oM = oF.Items(nn)
Debug.Print oM.Subject
Debug.Print oM.Body
Debug.Print oM.Attachments.Session
Debug.Print oM.Attachments.Parent
NumberOfAttachments = oM.Attachments.Count
If NumberOfAttachments > 0 Then
For pp = 1 To NumberOfAttachments
Debug.Print oM.Attachments(pp).Display Name
Next pp
End If
Next
End Sub
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
Sub TestMail()
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("
Set oF = olNS.GetDefaultFolder(olFo
For nn = oF.Items.Count To 1 Step -1
Set oM = oF.Items(nn)
Debug.Print oM.Subject
Debug.Print oM.Body
Debug.Print oM.Attachments.Session
Debug.Print oM.Attachments.Parent
NumberOfAttachments = oM.Attachments.Count
If NumberOfAttachments > 0 Then
For pp = 1 To NumberOfAttachments
Debug.Print oM.Attachments(pp).Display
Next pp
End If
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
(Reading your code makes me realize how little I really know about programming!)