我们可以从图 API 响应中获取 from/sender 和收件人电子邮件吗?

Can we get the from/sender and Recipient emails from graph API response?

如果附件不可用,我正在尝试转发电子邮件。我能够使用代码将电子邮件移动到另一个文件夹,但我不明白如何获取电子邮件地址。

下面是我写的代码。

if (ErrorFolder.DisplayName == "Error")
{
  var MessageID2 = Message.Id;
  var ErrorFolderId = ErrorFolder.Id;
  
 var MsgDetails = await graphClient.Me.MailFolders["Inbox"]
   .ChildFolders[$"{FirstSubFolderID.Id}"]
   .ChildFolders[$"{SecondSubFolderID.Id}"]
   .ChildFolders[$"{ErrorFolderId}"]
   .Messages[$"{MessageID2}"]
   .Request()
   .Select(em => new
   {
     em.Subject,
     em.From
   })
   .GetAsync();
 //var msg = MsgDetails.From;

 Console.WriteLine("Email Subject: {0}", MsgDetails.Subject);
 Console.WriteLine("From Email: {0}", MsgDetails.From);
}

来自 属性 returns 的值如下(根据图表文档)。

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('ee4376d7-d243-47a9-9729-dd398d0d1e5a')/mailFolders('inbox')/childFolders('AQMkADRlMDQwMjliLWU5NjItNDE5My05YjQ3LWJlNGRjYwBiZDM0MGEALgAAA2sRhR3zhaNNonFGlS_1NfIBAKdBNt_yapZOqPO2vlH2EfEAAAJOOgAAAA%3D%3D')/childFolders('AAMkADRlMDQwMjliLWU5NjItNDE5My05YjQ3LWJlNGRjY2JkMzQwYQAuAAAAAABrEYUd84WjTaJxRpUvtTXyAQCnQTbfsmqWTqjztr5R9hHxAAAGdVmSAAA%3D')/childFolders('AAMkADRlMDQwMjliLWU5NjItNDE5My05YjQ3LWJlNGRjY2JkMzQwYQAuAAAAAABrEYUd84WjTaJxRpUvtTXyAQCnQTbfsmqWTqjztr5R9hHxAAAdYEb3AAA%3D')/messages(from)/$entity",
    "@odata.etag": "W/\"CQAAABYAAACnQTbfsmqWTqjztr5R9hHxAAAdWOKS\"",
    "id": "AAMkADRlMDQwMjliLWU5NjItNDE5My05YjQ3LWJlNGRjY2JkMzQwYQBGAAAAAABrEYUd84WjTaJxRpUvtTXyBwCnQTbfsmqWTqjztr5R9hHxAAAdYEb3AACnQTbfsmqWTqjztr5R9hHxAAAdYGJwAAA=",
    "from": {
        "emailAddress": {
            "name": "Sandaruwan Samaraweera",
            "address": "sandaruwan.s@pro-account.lk"
        }
    }
}

我想获取 from 下的 2 个值,然后在将电子邮件转发回发件人时使用它们。这能做到吗?

你可以试试这个,我这边很管用:

var a = await graphClient.Me.MailFolders["Inbox"]
                .Messages["message_id"]
                .Request()
                .Select(em => new
                {
                    em.Subject,
                    em.From
                })
                .GetAsync();
var b = a.From.EmailAddress.Name;
var c = a.From.EmailAddress.Address;