使用比较运算符在 Outlook C# 中创建自定义字段过滤器

Using comparison operator to create custom field filter in Outlook C#

我创建了一个过滤器,用于比较自定义用户属性的值并仅显示符合要求的电子邮件。

过滤器在我有 = 比较值时有效,但在我有 <= 运算符时不起作用。

下面是我的过滤器。 这行得通。

string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" = '60'"; 
Outlook.Items restrictedMails = selectedFolder.Items.Restrict(filter);

这行不通。

string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" <= '60'"; 
Outlook.Items restrictedMails = selectedFolder.Items.Restrict(filter);

在自定义文件中保存值的代码如下。

int duration = (int)completed.Subtract(received).TotalMinutes;
try
                {
                    MailUserProperties = SelectedMail.UserProperties;
                    MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olText, true, 1);
                    MailUserProperty.Value = duration;
                    SelectedMail.Save();
                }

任何人都可以在这里帮助如何让过滤器工作吗?

提前致谢。

 string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" = '60'";

这里的60不是数字,是字符串。所以,基本上,比较两个字符串。

 MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olText, true, 1);

您添加了一个字符串用户 属性,然后想要应用比较器。它只对整数值有意义。所以,代码应该像下面这样:

 MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olInteger, true, 1);

然后您才可以尝试使用以下过滤器:

 string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" <= 60";