我正在尝试查找所有帐户中 Outlook 联系人中特定电子邮件地址的出现次数,无论它们是 POP/IMPA 还是 Exchange 帐户。我做了类似的事情,在收件箱中检测到“收件人”电子邮件地址与输入电子邮件地址匹配的电子邮件数量。
这是函数。当我取下过滤器时,效果很好。所以问题出在过滤器上,但是,我无法找到正确的属性值(看起来像这样的部分:0x8083001F) 我绑定了 Dmitry Streblechenko 的 OutlookSpy,但没有成功。指示具有输入电子邮件地址的联系人数量的行数始终为零,尽管我有使用此电子邮件地址的联系人...
我希望有人能告诉我正确的十六进制属性。
` private (int, int, int) SearchContactsInFolder(string emailAddress, Outlook.MAPIFolder Subfolder)//, BackgroundWorker worker)
{
using (Log.VerboseCall())
{
Log.VerboseFormat("Begin scanning contacts in {0}", Subfolder.Name);
if (Subfolder.DefaultItemType != Outlook.OlItemType.olContactItem)
{
string msg = $"Skipping folder {Subfolder.Name} of type {Subfolder.DefaultItemType.ToString()}";
Log.Verbose(msg);
throw new Exception(msg);
}
Outlook.Table table = null;
Outlook.Items contactItems = null;
int toCount = 0;
int ccCount = 0;
int bccCount = 0;
// 0x800F101F 0x39FE001E
//string filterTo = $"@SQL=\"http://schemas.microsoft.com/mapi/proptag/0x8083001F\" LIKE '%{emailAddress}%'";
//string filterTo = $"@SQL=\"http://schemas.microsoft.com/mapi/proptag/0x3A17001F\" = '{emailAddress}'";
string filterTo = $"@SQL=\"http://schemas.microsoft.com/mapi/proptag/0x39FE001E\" = '{emailAddress}'";
string filterCC = $"@SQL=\"http://schemas.microsoft.com/mapi/proptag/0x8093001F\" = '{emailAddress}'";
string filterBCC = $"@SQL=\"http://schemas.microsoft.com/mapi/proptag/0x80A3001F\" = '{emailAddress}'";
try
{
contactItems = Subfolder.Items;
if (contactItems != null && contactItems.Count > 0)
{
int iOutlookContacts = contactItems.Count;
Log.VerboseFormat("Number of Outlook contacts {0} folder: {1}", Subfolder.Name, iOutlookContacts.ToString());
// Count occurrences in 'To'
table = Subfolder.GetTable(filterTo, OlTableContents.olUserItems);
if (table != null)
{
toCount = table.GetRowCount();
Marshal.ReleaseComObject(table);
table = null;
}
// Count occurrences in 'CC'
table = Subfolder.GetTable(filterCC, OlTableContents.olUserItems);
if (table != null)
{
ccCount = table.GetRowCount();
Marshal.ReleaseComObject(table);
table = null;
}
// Count occurrences in 'CC'
table = Subfolder.GetTable(filterBCC, OlTableContents.olUserItems);
if (table != null)
{
bccCount = table.GetRowCount();
Marshal.ReleaseComObject(table);
table = null;
}
}
}
catch (Exception ex)
{
Log.Verbose(ex);
throw;
}
finally
{
if (contactItems != null) Marshal.ReleaseComObject(contactItems);
if (table != null) Marshal.ReleaseComObject(table);
}
return (toCount, ccCount, bccCount);
}
}`
尝试了各种属性代码。 尝试过 Outlook Spy。
您正在对命名属性标签进行硬编码 (
http://schemas.microsoft.com/mapi/proptag/0x8093001F
) - 不要这样做。查看 OutlookSpy 在 DASL 属性名称编辑框中显示该属性的内容。