Create mail item with mail item as attachment

E

eselk

I'll admit I haven't looked into this at all, and I'm just hoping for a
pretty quick answer from someone who has done this. I'd like to create
an email with another email inside it (as an attachment), and possibly
the attached email will have another email attached to it, and so on
and so on. Outlook does this when you forward multiple messages at
once, and it generates a message/rfc822 MIME type when sending.

I can use MAPI or OLE (OOM). All of the emails are generated dynamicly
and are not "linked" to any existing emails in Outlook. I'd like to be
able to create one email item with possibly 100s of other mail items
inside of it and not have these other 100s of mail items show up as
seperate emails anywhere in the inbox or other folders.

When I use Outlook Spy I can see that Outlook creates Attachment
objects (IAttach) for each attached email. The OLE DisplayName
property is set to the subject, and the FileName is an MSG file
(however, the MSG file doesn't exist on my hard-drive anywhere).

Can anyone point me in the right direction or let me know what problems
I'm going to run into?

Thanks!
 
E

eselk

Thanks Dmitry! Also, does the "SomeOtherMailItemObject" need to be
saved? If so, do I need to save it with some special flags so that it
isn't visible to the user? The only way the user should be able to see
this special mail item is as an attachment.
 
D

Dmitry Streblechenko

In Extended MAPI, yes, you can add an embedded message attachment without
creating a separate message. In Outlook Object Model the message to be
attached must exist as a regulat mesage first.
The only workaround is to delete the message immediately after you add it as
an attachment.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
E

eselk

Been on vacation for a while... I'm already mixing OOM and Extended
MAPI, so using Extended MAPI is no problem if that is what it takes.
Can you give me an example, or point me in the right direction, of how
I would go about doing this with Extended MAPI? I already add normal
attachments, and even HTML content attachments, using Extended MAPI, so
I imagine I've got most of the code. I get the IMessage interface,
then use CreateAttach to get an IAttach interface, then I set the
properties for that and stream the PR_ATTACH_DATA_BIN property. I
imagine I need to create another IMessage object, set some special
properties on the IAttach object, and then stream in the IMessage
object, and then delete the IMessage object without actually saving
it... but I'm not sure about the details, and of course this type of
stuff isn't documented (not that I can find anyway).
 
D

Dmitry Streblechenko

No, you will need to create a new attachment, set the PR_ATTACH_METHOD
property to ATTACH_EMBEDDED_MSG, open the PR_ATTACH_DATA_OBJ as IMessage (
IAttach::OpenProperty(PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_CREATE |
MAPI_MODIFY, &pNewMsg)), set the required properties on the embedded
message, save it, then save the attachment.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

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