Dear Dmitry,
I am using Extended MAPI.
I have .Msg file.
I first import the .msg file and get the MessagePtr.
and then try to read the SMTP address but i am getting Exchange version
of address.
I tried to use PR_SMTP_ADDRESS or PR_EMS_AV_PROXY_ADDRESSES,but it
gives
me error "Undeclared identifier" in VC++.
Here i am pasting my code please have a look at it.
//////////////////// Load the Msg file //////////////////////////////
HRESULT LoadFromMSG(LPTSTR lpMessageFile)// lpMessageFile = c:\\1.msg
(for ex)
{
HRESULT hRes = S_OK;
LPSTORAGE pStorage = NULL;
LPMESSAGE pIMsg = NULL;
LPWSTR lpWideCharStr = NULL;
ULONG cbStrSize = 0L;
LPSPropProblemArray lpProblems = NULL;
LPMALLOC pMalloc = NULL;
MAPIInitialize(NULL);
// get memory allocation function
pMalloc = MAPIGetDefaultMalloc();
// Convert new file name to WideChar
cbStrSize = MultiByteToWideChar (CP_ACP,
MB_PRECOMPOSED,
lpMessageFile,
-1, lpWideCharStr, 0);
hRes = MAPIAllocateBuffer ( cbStrSize * sizeof(WCHAR),
(LPVOID *)&lpWideCharStr );
MultiByteToWideChar (CP_ACP,
MB_PRECOMPOSED,
lpMessageFile,
-1, lpWideCharStr, cbStrSize );
// Open the compound file
hRes = ::StgOpenStorage(lpWideCharStr,
NULL,
STGM_READWRITE | STGM_TRANSACTED,
NULL,
0,
&pStorage);
// if (!CHECKHRES(hRes)) goto Cleanup;
// Open an IMessage interface on an IStorage object
hRes = ::OpenIMsgOnIStg(NULL,
MAPIAllocateBuffer,
MAPIAllocateMore,
MAPIFreeBuffer,
pMalloc,
NULL,
pStorage,
NULL,
0,
0,
&pIMsg);
GetMsgTextAndProperties(pIMsg);
return S_OK;
}
//////////////////Getting Reciptient Address//////////////////////////
BOOL GetMsgTextAndProperties(IMessage *pIMessage)
{
IMAPITable *pIMAPITableRcpt;
hr = pIMessage->GetRecipientTable(0,&pIMAPITableRcpt);
if (hr==S_OK)
{
SizedSPropTagArray(1,rcols) = {1, {PR_EMAIL_ADDRESS} };
SRowSet *rrows;
hr =
HrQueryAllRows(pIMAPITableRcpt,(SPropTagArray*)&rcols,NULL,NULL,0,&rrows);
if (hr==S_OK)
{
for (unsigned int r=0; r<rrows->cRows; r++)
{
CString strRecipient="";
if (rrows->aRow[r].lpProps [1].ulPropTag==PR_EMAIL_ADDRESS)
{
strRecipient = "<";
strRecipient += rrows->aRow[r].lpProps[0].Value.lpszA; // here i
am getting exchange format
strRecipient += ">";
}
}
FreeProws(rrows);
}
//IMAPITableRcpt->Release();
}
}
the code is perfect but it give me address in exchage format.
Regards,
Vinkal
//////////////////////////////////////////////////////////////////////
Dmitry said:
You will need to read PR_SMTP_ADDRESS or PR_EMS_AV_PROXY_ADDRESSES
property
using Extended MAPI/CDO 1.21/Redemption:
http://www.outlookcode.com/d/code/getsenderaddy.htm#redemption
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool