I'm trying to find a given contact using email for search email in a given folder folder using this method
private static ContactItem FindContactByEmail(MAPIFolder folder, string email,string email2)
{
string filter = $"[Email1Address]='{email}'";
$" used search filter [{filter}]".AddToLog();
try
{
var result = folder.Items.Find(filter);// i tried folder.Items.Restrict(filter) too
if (result!=null)
{
return result;
}
else
{
$"can't find {email} at {folder.FullFolderPath}".AddToLog();
}
}
catch(System.Exception r)
{
$"exception at FindContactByEmail {r.Message}".AddToLog();
}
// If the contact was not found in the current folder, search in its subfolders
foreach (MAPIFolder subfolder in folder.Folders)
{
var contact = FindContactByEmail(subfolder, email,email2);
if (contact != null)
{
return contact;
}
}
return null;
}
i doubled checked that the contact exists in my folder but the method can't find it, it only find it at Recipient Cache folder missing all the contact details like phone numbers
If the contact was created from a GAL entry,
Email1Addresswill contain the EX type address, not SMTP. You can either:AddressEntry.Addresswill give you that)Email1OriginalDisplayName. It is not directly exposed by theContactItemobject, but you can see it in OutlookSpy (I am its author) if you click the Message button. It can be accessed in OOM throughContactItem.Property.GetProperty; the DASL property name ishttp://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/8084001F. If you need to search against that property usingItems.Find/Restrict, you need to use the @SQL syntax: