Attachment added via MAPI not visible in preview pane

Joined
Apr 24, 2009
Messages
4
Reaction score
0
Hi,
I'm making an addIn for outlook which is adding the attachments to the incoming message. I had problems using MailItem.Attachments.Add method so I have used MAPI Ex method to add attachments. I have a problem that attachments larger then 100K are not visible in the message window when the message is stored in folder. There is indicator in explorer window that message contains attachments, and they can be seen and opened(right click on the message, View->Attachments). The code that I'm using is shown bellow. After the outlook is restarted the attachments are visible.Any ideas what I might be doing wrong?

Thanks

Vladimir

__declspec(dllexport) HRESULT AddAttachment(LPMESSAGE message, LPSTR pszFileName, int pathLen, char* src, int size)
{

LPATTACH pAttach = NULL;
ULONG ulAttNum;
HRESULT hRes;

SPropValue *oneProp = NULL;

enum {METHOD,ATTACH_FILENAME,ATTACH_LONG_FILENAME,ATTACH_PATHNAME,ATTACHMENT_FLAGS,ATTACH_SIZE,NUM_ATT_PROPS};

SPropValue props[NUM_ATT_PROPS];

SPropProblemArray* probs=NULL;
LPSTREAM pStrmDest = NULL;
ULONG bytesWritten = 0;



// Create an attachment on the message
if (FAILED(hRes = message->CreateAttach(NULL, (ULONG)0, &ulAttNum, &pAttach)))
{

goto Quit;
}

props[METHOD].ulPropTag =PR_ATTACH_METHOD;

props[METHOD].Value.l =ATTACH_BY_VALUE;


//set standard file properties
props[ATTACH_PATHNAME].ulPropTag =PR_ATTACH_PATHNAME;

props[ATTACH_PATHNAME].Value.lpszA =pszFileName;

props[ATTACH_FILENAME].ulPropTag =PR_ATTACH_FILENAME;

props[ATTACH_FILENAME].Value.lpszA = pszFileName;
props[ATTACH_LONG_FILENAME].ulPropTag =PR_ATTACH_LONG_FILENAME;

props[ATTACH_LONG_FILENAME].Value.lpszA =pszFileName;


props[ATTACH_PATHNAME].ulPropTag =PR_ATTACH_PATHNAME;

props[ATTACH_PATHNAME].Value.lpszA =pszFileName;

props[ATTACHMENT_FLAGS].ulPropTag = PR_ATTACHMENT_FLAGS;
props[ATTACHMENT_FLAGS].Value.l = 0;

props[ATTACH_SIZE].ulPropTag = PR_ATTACH_SIZE;
props[ATTACH_SIZE].Value.l = size;

if(FAILED(hRes=pAttach->SetProps(NUM_ATT_PROPS, props, &probs)))
{

goto Quit;
}

//pAttach -> SaveChanges(0);

if (FAILED(hRes = pAttach->OpenProperty(
PR_ATTACH_DATA_BIN,
(LPIID)&IID_IStream,
STGM_WRITE,
MAPI_CREATE|MAPI_MODIFY ,
(LPUNKNOWN *)&pStrmDest)))
{

goto Quit;
}


pStrmDest->Write(src,size,&bytesWritten);


pStrmDest->Commit(0);

// Save the changes to the Attachment
pAttach -> SaveChanges(0);

message->SaveChanges(KEEP_OPEN_READWRITE);

// message->Release();*/

Quit:
if(pStrmDest)
pStrmDest -> Release();
if (pAttach)
pAttach -> Release();

return hRes;
}
 
Back
Top