Thomas Grossen
Guest
|
Hi again,
Do you have any example in Delphi about how to get the e-mail senders address using MAPI (for Outlook version < 2003)?
Thank you. |
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
Hi Thomas,
We don't have such an example. But if you have some working code written in another programming language, you can send it to me, I will try to convert it to Delphi.
P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
|
|
Thomas Grossen
Guest
|
Dmitry,
Hi Dmtry,
here is the code that I am using in the .NET version. I have written the code using Sergey's sample:
http://www.add-in-express.com/projects/getsenderemailexample.zip
So if you have something that can help me in Delphi I would be grateful :)
static public string GetSendersEmailAdress(Outlook._MailItem oMail)
{
string senderEmail = String.Empty;
object mapiObject = null;
mapiObject = oMail.MAPIOBJECT;
if (mapiObject != null)
{
string senderType = String.Empty;
IntPtr unk = IntPtr.Zero;
IntPtr unkObj = IntPtr.Zero;
try
{
unkObj = Marshal.GetIUnknownForObject(mapiObject);
Guid iMapiProp = new Guid("00020303-0000-0000-C000-000000000046");
Marshal.QueryInterface(unkObj, ref iMapiProp, out unk);
if (unk != IntPtr.Zero)
{
IntPtr pPropValue = IntPtr.Zero;
try
{
MAPI.HrGetOneProp(unk, MAPI.PR_SENDER_EMAIL_ADDRESS, out pPropValue);
MAPI.SPropValue propValue = (MAPI.SPropValue)Marshal.PtrToStructure(pPropValue, typeof(MAPI.SPropValue));
propValue.Value &= 0xFFFFFFFF;
senderEmail = Marshal.PtrToStringAnsi(new IntPtr(propValue.Value));
}
catch
{
}
if (pPropValue != IntPtr.Zero)
MAPI.MAPIFreeBuffer(pPropValue);
/* To get Senders Address Type ("EX" "SMTP")
IntPtr pPropValue = IntPtr.Zero;
try
{
MAPI.HrGetOneProp(unk, MAPI.PR_SENDER_ADDRTYPE, out pPropValue);
MAPI.SPropValue propValue = (MAPI.SPropValue)Marshal.PtrToStructure(pPropValue, typeof(MAPI.SPropValue));
propValue.Value &= 0xFFFFFFFF;
senderType = Marshal.PtrToStringAnsi(new IntPtr(propValue.Value));
}
catch
{
}
if (pPropValue != IntPtr.Zero)
MAPI.MAPIFreeBuffer(pPropValue);
*/
}
}
finally
{
Marshal.Release(unkObj);
if (unk != IntPtr.Zero) Marshal.Release(unk);
Marshal.ReleaseComObject(mapiObject);
}
}
return senderEmail;
}
|
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
|
Thomas Grossen
Guest
|
Hi,
Thank you for the sample; it works perfectly! :D
|
|