Hello everyone,
I'm trying to insert a .msg file as an embedded message attachment in a
message but the embedded message which gets created is not valid and I
cannot open it in Outlook. Here is what I do.
1.) Create embedded attachment on pIMsg (parent message) using CreateAttach
2.) Set PR_ATTACH_METHOD on attachment
3.) Load xyz.msg file to IMessage lpSrcEmbMsg
4.) Open PR_ATTACH_DATA_OBJ property of attachment as IMessage lpEmbdMsg
5.) Copy Source msg properties to attachment using CopyTo
6.) SaveChanges on embedded message, set other attachment properties, save
attachment and save parent message
The code snippet is below. Can someone suggest me what's wrong with this
code?
if(ATTACH_EMBEDDED_MSG == ulAttachMethod)
{
pIMsg->CreateAttach(NULL, 0, &ulAttachNum, &lpAttach);
Prop.ulPropTag = PR_ATTACH_METHOD;
Prop.Value.l = ulAttachMethod ;
hr = HrSetOneProp((IMAPIProp*)lpAttach, &Prop);
LPMESSAGE lpEmbdMsg = NULL;
LPMESSAGE lpSrcEmbMsg = NULL;
LoadMSGToMessage("XYZ.msg", &lpSrcEmbMsg);
lpAttach->OpenProperty(PR_ATTACH_DATA_OBJ, &IID_IMessage, 0,
MAPI_CREATE|MAPI_MODIFY, (LPUNKNOWN *)&lpEmbdMsg)))
hr = lpSrcEmbMsg->CopyTo(0, NULL, NULL, NULL, NULL,(LPIID)&IID_IMessage,
lpEmbdMsg, 0, NULL);
lpEmbdMsg->SaveChanges(0);
lpEmbdMsg->Release();
lpEmbdMsg= NULL;
lpSrcEmbMsg->Release();
lpSrcEmbMsg = NULL;
}
// SET PROPERTIES ON lpAttach HERE
lpAttach->SaveChanges(0);
pIMsg->SaveChanges(0);
Thanks in advance!
Varun