无法通过SingleValueExtendedProperty找到特定的消息

问题描述

我有一个应用程序尝试使用Microsoft Graph发送电子邮件,然后检索相同的消息以将一些信息导入到我们的数据库中。

研究此问题后,建议的技巧是将独特的信息附加到邮件中,然后使用该值搜索邮件。对于图形/邮件,该方法为SingleValueExendedProperty

我可以在应用程序和LinqPad环境中进行测试。但是,我越来越少了该图的实例,无法找到该电子邮件。我跟踪了消息,并通过消息跟踪找到了InternetId,并一直试图解决问题。

我可以使用InternetId从Graph SDK中获取消息,但不能使用SingleValueExtendedProperty,即使在以下情况下我可以在消息上看到SingleValueExtendedProperty的确切值:通过InternetId检索,似乎只是发送了特定的消息而不是全部消息都是一个问题。我开始怀疑Graph有问题吗?

我的代码中使用的GUID只是内部日志/事件ID,因此它们并不是真正的秘密,出于安全原因,其余敏感信息已被忽略。

以下是我在LinqPad中使用软件包Microsoft.Graph 3.12.0,Microsoft.Identity.Client 4.18.0和Microsoft.Graph.Auth 1.0.0-preview5进行测试的代码>

Guid propertyNamespace = Guid.Parse("75CF8950-C01A-4D68-850D-13E7E49C12C0"); //Just a random GUID to use as my namespace

async Task Main()
{
    //Just including these to be thorough,obviously the real values are omitted for security
    var clientId = "";
    var tenantId = "";
    var secret = "";

    var clientApplication = Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.Create(clientId)
            .WithAuthority(Microsoft.Identity.Client.AzureCloudInstance.AzurePublic,tenantId)
            .WithClientSecret(secret)
            .Build();

    var authProvider = new Microsoft.Graph.Auth.ClientCredentialProvider(clientApplication);
    var graphClient = new Microsoft.Graph.GraphServiceClient(authProvider);

    //This will locate the message correctly
    var messageById = await GetMessage(graphClient,"user.name@example.com","ABCDEF1234567890@FAKE.CANPRD01.PROD.OUTLOOK.COM"); //Fake `InternetId`,but you get the point

    //This will not find the message
    var messageByProperty = await GetMessage(graphClient,"EventId",Guid.Parse("6c105c1e-cb55-4ba4-90f6-ac2b01084a54"));

    var propertyFoundById = messageById.SingleValueExtendedProperties.Single();
    $"'{propertyFoundById.Id}' '{propertyFoundById.Value}'".Dump("propertyFoundById");
    $@"singleValueExtendedProperties/Any(ep: ep/id eq 'String {propertyNamespace:B} Name {"EventId"}' and ep/value eq '{Guid.Parse("6c105c1e-cb55-4ba4-90f6-ac2b01084a54")}')".Dump("Expression when filtering by property");

    /*
    The above two Dump() statements will spit out the following strings respectively

    'String {75cf8950-c01a-4d68-850d-13e7e49c12c0} Name EventId' '6c105c1e-cb55-4ba4-90f6-ac2b01084a54' 

    singleValueExtendedProperties/Any(ep: ep/id eq 'String {75cf8950-c01a-4d68-850d-13e7e49c12c0} Name EventId' and ep/value eq '6c105c1e-cb55-4ba4-90f6-ac2b01084a54') 
    */
}

///<summary>A method to locate a message by searching with the SingleValueExtendedProperties</summary>
private async Task<Microsoft.Graph.Message> GetMessage(Microsoft.Graph.GraphServiceClient graphClient,string mailbox,string propertyName,Guid propertyValue)
{
    var message = (await graphClient.Users[mailbox].MailFolders["SentItems"].Messages.Request()
        .Filter($@"singleValueExtendedProperties/Any(ep: ep/id eq 'String {propertyNamespace:B} Name {propertyName}' and ep/value eq '{propertyValue}')")
        .Expand($"singleValueExtendedProperties($filter=id eq 'String {propertyNamespace:B} Name EventId')")
        .GetAsync())
        .SingleOrDefault();
    return message;
}

///<summary>A method to locate a message by searching with the InternetId<summary>
private async Task<Microsoft.Graph.Message> GetMessage(Microsoft.Graph.GraphServiceClient graphClient,string internetId)
{
    var message = (await graphClient.Users[mailbox].MailFolders["SentItems"].Messages.Request()
        .Filter($@"internetMessageId eq '<{internetId}>'")
        .Expand($"singleValueExtendedProperties($filter=id eq 'String {propertyNamespace:B} Name EventId')")
        .GetAsync())
        .SingleOrDefault();
    return message;
}

我检查了InternetId查找到的消息的SingleValueExtendedProperty,并将其与其他方法中使用的过滤器表达式进行了比较,详细信息看起来相同。然而,这似乎是应用程序发送的电子邮件很少(大约175条中的3条)所特有的,因为如果我在LinqPad中发送新的电子邮件

var message = new Microsoft.Graph.Message();
message.SingleValueExtendedProperties = new Microsoft.Graph.MessageSingleValueExtendedPropertiesCollectionPage();
message.SingleValueExtendedProperties.Add(new Microsoft.Graph.SingleValueLegacyExtendedProperty { Id = $"String {propertyNamespace:B} Name {propertyName}",Value = Guid.Parse("11111111-2222-3333-4444-555555555555").ToString() });
/* Other fields excluded for brevity */
await graphClient.Users["user.name@example.com"].SendMail(message,true).Request().PostAsync();

然后,当我寻找此新消息时,我上面使用的两种GetMessage()方法(一种使用InternetId,另一种使用SingleValueExtendedProperties)都会找到相同的消息

我想知道是否还有其他人遇到此问题,或者是否应该知道某个已知问题?我很想尝试官方的支持选项,但是由于问题的具体程度,我不愿意尝试成为一个真正的人。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...