Outlook nested attachments

G

Gromit

I’m trying to programmatically manipulate e-mail attachments using VBA in Microsoft Outlook 2000. I have no problem if the e-mail contains the Attachment that I expect

However, from time to time, I have to manipulate an Attachment that is, in turn, a MailItem containing an Attachment and it is this nested Attachment that I’m trying to get at

How can I persuade my code that the Attachment is also a MailItem containing an Attachment

In principle, I feel I would like to cast my Attachment as a MailItem; I’d like to tell VBA, look if this Attachment is a MailItem then let me assign it to an object of type MailItem so that I can get to its Attachment collection

Alternatively, I would like the Attachment object to have an Attachments collection of its own

Any help would be most welcome
 
W

Wei-Dong Xu [MSFT]

Hi,

Thanks for posting in the community!

From your description, you are going to find one method to retrieve the
attachment of the attachment in one mailitem.

So far as I know, there is no one "cast" way, as you mentioned, existing
for this in Outlook object. I'd suggest one workaround can provide some
assistance for you. To retrieve the attachment in one attachment, you can
first save the first attachment into one .msg file and then open the msg
file, save the attachment in it into one msg file again. Then, open the
second msg file. This way, you can retrieve the information in the
attachment of one attachment. I create one sample codes for you on this.

'Code begin ----------------------------------------------------
Dim myOlapp As Outlook.Application
Dim myNamespace As NameSpace
Dim myfolder As MAPIFolder
Dim myItem As MailItem

Dim test2Item As MailItem

Set myOlapp = Application
Set myNamespace = myOlapp.GetNamespace("MAPI")
Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set myItem = myfolder.Items("aa")
Debug.Print myItem.Attachments.Count
Debug.Print myItem.Attachments.Class
Debug.Print myItem.Attachments.Item(1).Class
myItem.Attachments.Item(1).SaveAsFile "E:\test.msg"

'Open the attachement
Set myItem = Application.CreateItemFromTemplate("e:\test.msg")
If myItem.Attachments.Count = 1 Then
myItem.Attachments.Item(1).SaveAsFile "e:\test2.msg"
End If

Set test2Item = Application.CreateItemFromTemplate("e:\test2.msg")
test2Item.Display
'Code end ------------------------------------------------------

Furthermore, I think your cast suggestion is very cool. I'd recommend that
you forward this idea to the Microsoft Wish Program:
1. World Wide Web
a)In Internet Explorer 6, click Send Feedback on the Help menu and then
click the link in the Product Suggestion section of the page that appears.
b)In Windows XP, click Help and Support on the Start menu. Click Send
your feedback to Microsoft, and then fill out the Product Suggestion page
that appears.
c)Visit the following Microsoft Web site:
http://www.microsoft.com/ms.htm
d)Click Microsoft.com Guide in the upper-right corner of the page and
then click Contact Us . Click the link in the Product Suggestion section of
the page that appears.
e)Visit the following Microsoft Product Feedback Web site
http://register.microsoft.com/mswish/suggestion.asp
and then complete and submit the form.

2. E-mail - To send comments or suggestions via e-mail, use the following
Microsoft Wish Program e-mail address, (e-mail address removed).

3. FAX - To send comments or suggestions via FAX, use the following
Microsoft FAX number, (425) 936-7329.
NOTE : Address the FAX to the attention of the Microsoft Wish Program.

4. US Mail - To send comments or suggestions via US Mail, use the following
Microsoft mailing address:
Microsoft Corporation
Attn. Microsoft Wish Program
One Microsoft Way
Redmond, WA 98052-6399

Please feel free to let me know if you have any further questions. I am
standing by to be of assistance.

Enjoy a nice weekend!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Gromit

Dear Wei-Dong Xu

Thanks very much indeed; your suggestion works and I can use it to get to nested attachments / messages

The key, which I had not realised could be used in this way, is the CreateItemFromTemplate method of the Application object which appears to get instances of MailItems saved in the file system back into the MAPI namespace. I had wondered about a similar idea but I thought I needed the CopyFile method of the Application object, which did not exist until Outlook 2002

I think this workaround, although effective, is very inelegant and so I will follow your advice and send a message to the Microsoft Wish Program

Once again, many thanks and you have a good weekend too

Paul
 
W

Wei-Dong Xu [MSFT]

Hi Paul,

It is very happy for me to hear that! Have a nice day!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top