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