Get Sender's Email Address

  • Thread starter Thread starter Vinayakc
  • Start date Start date
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
 
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.
 
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
 
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
 
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
 
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
 
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
 
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.
 
Back
Top