MSGraph/Messages返回ldap路径?而不是实际地址

huangapple go评论65阅读模式
英文:

MSGraph/Messages returns ldap-path? instead of actual address

问题

在解析某些电子邮件时,我遇到了这个问题,这些电子邮件是发送给我的:

var email_ids = await Graph
    .Users[user.Id]
    .MailFolders[SrcFolderId]
    .Messages.Request()
    .Select(x => new { Id = x.Id, Subject = x.Subject, From = x.From, Received = x.ReceivedDateTime, Sender = x.Sender })
    .GetAsync();

foreach (var msg in email_ids)
{
    var from = msg.From.EmailAddress.Address;
    // 返回:"/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=A744B91971114B01B89FD0C4B28F412F-JANECKI MAR"
}

在其他电子邮件中,这个属性是有效的。这是一个错误还是一个特性?

英文:

So when parsing some emails I encountered this problem on emails sent to myself:

 var email_ids = await Graph
                .Users[user.Id]
                .MailFolders[SrcFolderId]
                .Messages.Request()
                .Select(x=> new { Id=x.Id,Subject = x.Subject,From = x.From,Received = x.ReceivedDateTime,Sender = x.Sender})
                .GetAsync();

                foreach (var msg in email_ids)
                {
                   var from = msg.From.EmailAddress.Address; 
                   //returns:"/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=A744B91971114B01B89FD0C4B28F412F-JANECKI MAR"
                } 

On other emails the attribute works. bug or feature?

答案1

得分: 0

Exchange始终以其本机EX格式存储电子邮件地址,通常在您查询时,Graph将解析它们(从目录中,例如AAD)。但是,如果用户已被删除(或邮箱已迁移且地址不再有效),则无法再解析它们,而只会返回本机地址。还有一些边缘情况,在这些情况下,当您列举消息时,只需在电子邮件ID端点(/messsage/{id})上执行Get操作即可(但在限制方面确实非常昂贵)。

我建议的是,如果您始终需要SMTP地址,请在查询中包含https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagsendersmtpaddress-canonical-property,在这种情况下,如果返回EX地址,您将始终拥有SMTP地址,而无需进行任何额外的查询。例如:

.Users[user.Id]
.MailFolders[SrcFolderId]
.Messages.Request()
.Expand("singleValueExtendedProperties($filter=id eq 'String 0x5D01')")
.Select(x => new { Id = x.Id, Subject = x.Subject, From = x.From, Received = x.ReceivedDateTime, Sender = x.Sender, SingleValueExtendedProperties = x.SingleValueExtendedProperties})
.GetAsync();

在v5中,类似于以下内容:

string selectList = "Id,Subject,From,ReceivedDateTime,Sender,SingleValueExtendedProperties";
string exProp = "singleValueExtendedProperties($filter=id eq 'String 0x5D01')";
var messages = graphServiceClient.Users[userId].MailFolders["inbox"].Messages.GetAsync(requestConfiguration =>
{
    requestConfiguration.QueryParameters.Select = new string[] { selectList };
    requestConfiguration.QueryParameters.Expand = new string[] { exProp };
}).GetAwaiter().GetResult().Value.Select(x => new { Id = x.Id, Subject = x.Subject, From = x.From, Received = x.ReceivedDateTime, Sender = x.Sender, SingleValueExtendedProperties = x.SingleValueExtendedProperties });
foreach(var message in messages)
{
    Console.WriteLine(message.Sender);
}
英文:

Exchange always stores email addresses in it's Native EX format and the Graph will generally resolve them (from the the directory eg AAD) when you make the query. However if the user has been deleted (or the mailbox has been migrated and the address is no longer valid) it can't resolve them anymore and will just return the native address. There are also some edge cases where this happens when you enumerate messages in those cases just doing a Get on the email id endpoint (/messsage/{id}) should work (but is really expensive in terms of throttling).

What i would suggest is if your always need the SMTP address is include https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagsendersmtpaddress-canonical-property in your query in the case you get a EX address returned then you will always have the SMTPaddress available without needing to make any extra queries. eg

           .Users[user.Id]
           .MailFolders[SrcFolderId]
           .Messages.Request()
           .Expand("singleValueExtendedProperties($filter=id eq 'String 0x5D01')")
           .Select(x => new { Id = x.Id, Subject = x.Subject, From = x.From, Received = x.ReceivedDateTime, Sender = x.Sender, SingleValueExtendedProperties = x.SingleValueExtendedProperties})
           .GetAsync();

in v5 something like

        string selectList = "Id,Subject,From,ReceivedDateTime,Sender,SingleValueExtendedProperties";
        string exProp = "singleValueExtendedProperties($filter=id eq 'String 0x5D01')";
        var messages = graphServiceClient.Users[userId].MailFolders["inbox"].Messages.GetAsync(requestConfiguration =>
        {
            requestConfiguration.QueryParameters.Select = new string[] { selectList };
            requestConfiguration.QueryParameters.Expand = new string[] { exProp };
        }).GetAwaiter().GetResult().Value.Select(x => new { Id = x.Id, Subject = x.Subject, From = x.From, Received = x.ReceivedDateTime, Sender = x.Sender, SingleValueExtendedProperties = x.SingleValueExtendedProperties });
        foreach(var message in messages)
        {
            Console.WriteLine(message.Sender);
        }

huangapple
  • 本文由 发表于 2023年6月6日 14:42:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412050.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定