How to get Recipient's SMTP Address from Exchange Address in VC++

V

vinkal.chudgar

Hi,

I am Developing COM Addin in VC++/ATL.

I am using Outlook 2003 connected to Exchange 5.5.

when i try to get Recipient's Email address (TO address),i am getting
address in exchange format like

"/O=Emsure.com/OU=EmSure0/CN=RECIPIENTS/CN=Vinkal" but

i want to get this address in SMTP address like (e-mail address removed).

I have managed to get From Address in SMTP format using CDO.

but i can't find any solutions for getting to address in SMTP format.

It would be grateful to me if someone could give me small code for
getting "TO address" (Recipients address) in VC++.

Regards,

Vinkal.
 
V

vinkal.chudgar

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

//////////////////////////////////////////////////////////////////////
 
D

Dmitry Streblechenko

You either need to include the appropriate header files (edkmdb.h?) or
define them explicitly in your code. Did you look at EX recipients with
AbView or OutlookSpy?

PR_SMTP_ADDRESS = 0x39FE001E
PR_EMS_AB_PROXY_ADDRESSES = 0x800F101E

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

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
 

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