Retrieving Custom Header

H

Haja

Hi,

I would need some idea to fix the problem of retrieving header from received
e-mail.

I am using the following code to retrieve header (e.g. From, To, Cc,
Message-ID) , my code is working good with my computer, but it doesn't
working with another computer.
Both computers are having WinXp OS.

This is my code:
------------------------------------------------------

private string GetHeader(object itemObj, string headerName)
{
IMAPIProp mail = null;
string retVal = String.Empty;

mail = itemObj as IMAPIProp;
if (mail != null)
{
IntPtr p = IntPtr.Zero;
IntPtr lpszStr = IntPtr.Zero;
IntPtr propTags = IntPtr.Zero;
IntPtr lpszValue = IntPtr.Zero;
IntPtr lpProblems = IntPtr.Zero;
IntPtr lpPropValue = IntPtr.Zero;
IntPtr _mapiNameID = IntPtr.Zero;
IntPtr lpPropArray = IntPtr.Zero;
SPropValue propValue = new SPropValue();
MAPINAMEID mapiNameID = new MAPINAMEID();
try
{
Guid g = new Guid(magicGUID);
_mapiNameID = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MAPINAMEID)));

p = Marshal.AllocHGlobal(Marshal.SizeOf(g));
Marshal.StructureToPtr(g, p, false);
mapiNameID.lpguid = p;
mapiNameID.ulKind = MAPI.MNID_STRING;
lpszStr = Marshal.StringToHGlobalUni(headerName);
mapiNameID.lpwstrName = lpszStr;
Marshal.StructureToPtr(mapiNameID, _mapiNameID, false);

if (mail.GetIDsFromNames(1, ref _mapiNameID, MAPI.MAPI_CREATE, out
propTags) == MAPI.S_OK)
{
int count = Marshal.ReadInt32(propTags);
if (count == 1)
{
uint cValues = 0;
if (mail.GetProps(propTags, MAPI.MAPI_UNICODE, out cValues, out
lpPropArray) == MAPI.S_OK)
{
if (cValues == 1)
{
uint pType = (uint)(Marshal.ReadInt32(lpPropArray) & 0xFFFF);
if (pType == MAPI.PT_ERROR)
{
//Marshal.ThrowExceptionForHR(Marshal.ReadInt32(lpPropArray));
}
else
{
int strAddr = Marshal.ReadInt32(new IntPtr(lpPropArray.ToInt32() +
8));
retVal = Marshal.PtrToStringAuto(new IntPtr(strAddr));
}
}
}
}
}
}
finally
{
if (lpPropArray != IntPtr.Zero)
MAPI.MAPIFreeBuffer(lpPropArray);
if (lpszValue != IntPtr.Zero)
Marshal.FreeHGlobal(lpszValue);
if (lpPropValue != IntPtr.Zero)
Marshal.DestroyStructure(lpPropValue, typeof(SPropValue));
if (propTags != IntPtr.Zero)
MAPI.MAPIFreeBuffer(propTags);
if (p != IntPtr.Zero)
Marshal.DestroyStructure(p, typeof(Guid));
if (lpszStr != IntPtr.Zero)
Marshal.FreeHGlobal(lpszStr);
if (_mapiNameID != IntPtr.Zero)
Marshal.DestroyStructure(_mapiNameID, typeof(MAPINAMEID));
}
}
return retVal;
}
--------------------------------------------------------------

Can anyone help me please

Thanks in advance
Haja
 
D

Dmitry Streblechenko

And when it does not work, do you get back an error code?
Or an unexpected result?
Are yo usre that property actually exists on the mesage in question? Can you
see it in MFCMAPI or OutlookSpy?

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

Haja

Dmitry,

Thanks for your reply. I am sure that property exists. When I use this code
I am getting expected answer in my computer, but when I run this dll in
another computer. It doesn't show any error, but produces empty values, rest
of the code working fine though.

After doing search in internet, I found a clue, the following link

http://support.microsoft.com/default.aspx/kb/184269#top

But still not sure...


Thanks
Haja
 
D

Dmitry Streblechenko

IF teh property exists on a particular mesage on your machene, does not mean
it will exist on another mesasge on another machine.
Download and install OutlookSpy on the poblematic machine and take a look at
the message (click IMessage).
You also need to check the error code returned by GetProps()
--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
H

Haja

Dmitry,

Can you please advice me some other way to get header. All I would need is
to get recipients (To and Cc) name and email addresses for receieved e-mails.
I am using the following tag namespace. It is working good with less then
nine (9) recipient addresses if recipient address goes more than nine, then
it is bring null value.

http://schemas.microsoft.com/mapi/proptag/0x007D001E )



Any otherway to do this

Thanks



:
 
D

Dmitry Streblechenko

Why do you even look at PR_TRANSPORT_HEADERS (which my not even exist)?
If you need message recipients, use the recipients table
(IMessage::GetRecipientTable)..
What exaxtly brings the null value? GetProps?

--
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