Get Sender's Email Address

V

Vinayakc

Hi,

I am unable to get the sender's email address of the mail item. I did
R&D lot but all solutions suggested to use CDO.
I dont want to use CDO.
I think PR_SENDER_EMAIL_ADDRESS MAPI property will help me but I dont
know how to access this MAPI property of Outlook mail item.
Please help me as soon as possible.

Thanking u in advance
regards
Vinayakc
 
K

Ken Slovak - [MVP - Outlook]

What API are you using? You can only use PR_SENDER_EMAIL_ADDRESS if you are
using CDO or Extended MAPI (C++ or Delphi only) or Redemption
(www.dimastr.com/redemption). That property isn't available directly in the
Outlook object model.

If you are coding for Outlook 2003 you could use SenderEmailAddress, but
unless you are writing a trusted COM addin that will fire the security
prompts.
 
V

Vinayakc

Thanks Ken,

Currently I am using extended MAPI.
My source code is like this:

//spMailItem is CComPtr<Outlook::_MailItem>

IUnknown* pUnknown;

IMessage *pMsg = NULL;

LPSPropValue lpsProp;


result = MAPIInitialize(NULL);

MAPIAllocateBuffer(sizeof(_SPropValue),(LPVOID*)&lpsProp);

spMailItem->get_MAPIOBJECT(&pUnknown);
pUnknown->QueryInterface(IID_IMessage, (void**)&pMsg);

result =
HrGetOneProp((LPMAPIPROP)pMsg,PR_SENDER_EMAIL_ADDRESS_W,(LPSPropValue
FAR *)&lpsProp);
if( result != S_OK )
{
LOG_ERR_MESSAGE( _T("HrGetOneProp()") , result );
//bRet = FALSE;
//goto Error;
return FALSE;
}

LPSTR hello;

hello =lpsProp->Value.lpszA;

if (lpsProp)
MAPIFreeBuffer(lpsProp);
lpsProp = NULL;
MAPIUninitialize();

My HrGetOneProp API is not working. It is returning some undefined
errorcode which is < 0.
I am new to Extended MAPI. So I could not figure out why this is
happening.

Thanks again
Regards
Vinayakc
 
D

Dmitry Streblechenko

What is that negative number returned by HrGetOneProp? Is it
MAPI_E_NOT_FOUND? Did you make sure PR_SENDER_EMAIL_ADDRESS actually exists
on the message in question? Did you look at that message with MdbView or
OutlookSpy?
Where does the message come from? Also note that you should not allocate
memory before calling HrGetOneProp - lpsProp will be allocated an populated
by HrGetOneProp (or IMessage::GetProps to be precise).

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

Vinayakc

Yes the error code return is : -2147221233 MAPI_E_NOT_FOUND.

I checked that mail's PR_SENDER_EMAIL_ADDRESS property with OutlookSpy.
It is showing me the mail address of sender.

Message is simple IPM.Note message.
I tried without allocating memory before calling HrGetOneProp. But it
is failing still.

I could not understand why it is happening??

one more thing. I can successfully access properties like
PR_MESSAGE_SIZE, PR_ENTRYID ut could not access PR_SENDER_EMAIL_ADDRESS
, PR_MESSAGE_CLASS.

Eagerly waiting for your help.

Thanks and Regards
Vinayakc
 
D

Dmitry Streblechenko

Are you *sure* it is the right message? Where does it come from
(folder.items, inspector, etc)? Did you try to read the PR_SUBJECT property
to verify that you are looking at the same message you check with
OutlookSpy?

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

Vinayakc

Hi Dmirty,

I have just solved this problem. Actually i was reading property
­PR_SENDER_EMAIL_ADDRESS_W

I have jsut changed it to
­PR_SENDER_EMAIL_ADDRESS_A
& it is working now. I am now trying to find out the cause behind it.
I have made the changes you suggested as not to allocate MAPI buffer.

Thank you very much for valuable suggestions.
Regards
Vinayakc
 
Joined
Nov 23, 2004
Messages
2
Reaction score
0
A Cheeky solution for you...

I had this problem some time ago.
The easiest solution I could find without using redemption etc was to post a reply method to the item.
This will return a new item with the sender now as the recipient!! - Here you should be able to access the recipients details without hitting the OMG.

Good Luck
Steve.
 

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