Outlook API获取邮件/邮件ID

时间:2018-03-12 15:57:45

标签: outlook exchangewebservices

我正在尝试创建使用Outlook API的应用。我想要创建的第一个功能是将Outlook Mail集成到我的应用程序中。但是当我尝试使用POST发送电子邮件时,我有回复电子邮件的问题:

  

POST:https://outlook.office.com/api/v2.0/Users/email/sendmail

{
    "Message": {
        "Subject": "Test",
        "Importance": "Normal",
        "ToRecipients": [{
            "EmailAddress": {
                "Address": "jaisanas2@gmail.com",
                "Name": "jais anas"
            }
        }],
        "Body": {
            "ContentType": "HTML",
            "Content": "Bangsaaaaat aneh"
        }
    },
    "SaveToSentItems": "true"
}

响应仅返回状态代码202 accepted正文为空,然后我研究并找到面临相同情况的人,如here

建议使用PR_SEARCH_KEY。我尝试嵌入PR_SEARCH_KEY,如下所示:

  

POST https://outlook.office.com/api/v2.0/me/messages

   {
    "Subject": "Test",
        "Importance": "Normal",
        "ToRecipients": [{
            "EmailAddress": {
                "Address": "jaisanas2@gmail.com",
                "Name": "jais anas"
            }
        }],
        "Body": {
            "ContentType": "HTML",
            "Content": "ultra aneh"
        },
    "SingleValueExtendedProperties": [
     {
           "PropertyId":"String {66f5a359-4659-4830-9070-00040ec6ac6e} Name Fun",
           "Value":"Food"
     }
  ],
  "IsDraft": false
}

它返回我所期望的响应:

 {
    "@odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/Messages/$entity",
    "@odata.id": "https://outlook.office.com/api/v2.0/Users('ae679c71-8bf5-4b97-bdf4-77139f637325@b3177487-e927-4ded-ba13-787dec0ebbca')/Messages('AAMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQBGAAAAAADuF3VB4SlIT6v3u7na6JIHBwCfoOdZk3FLQau_3XsCiAazAAAAAAEPAACfoOdZk3FLQau_3XsCiAazAAEpvIT5AAA=')",
    "@odata.etag": "W/\"CQAAABYAAACfoOdZk3FLQau+3XsCiAazAAEp7BTR\"",
    "Id": "AAMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQBGAAAAAADuF3VB4SlIT6v3u7na6JIHBwCfoOdZk3FLQau_3XsCiAazAAAAAAEPAACfoOdZk3FLQau_3XsCiAazAAEpvIT5AAA=",
    "CreatedDateTime": "2018-03-12T15:36:30Z",
    "LastModifiedDateTime": "2018-03-12T15:36:31Z",
    "ChangeKey": "CQAAABYAAACfoOdZk3FLQau+3XsCiAazAAEp7BTR",
    "Categories": [],
    "ReceivedDateTime": "2018-03-12T15:36:31Z",
    "SentDateTime": "2018-03-12T15:36:31Z",
    "HasAttachments": false,
    "InternetMessageId": "<PS1PR06MB124320CE100FA9B65B0A1753AAD30@PS1PR06MB1243.apcprd06.prod.outlook.com>",
    "Subject": "Test",
    "BodyPreview": "ultra aneh",
    "Importance": "Normal",
    "ParentFolderId": "AQMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQAuAAAD7hd1QeEpSE_r97u52uiSBwEAn6DnWZNxS0Grvt17AogGswAAAgEPAAAA",
    "ConversationId": "AAQkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQAQAHF_FKARNjtGuOFXHfrijQE=",
    "IsDeliveryReceiptRequested": false,
    "IsReadReceiptRequested": false,
    "IsRead": true,
    "IsDraft": true,
    "WebLink": "https://outlook.office365.com/owa/?ItemID=AAMkAGM4MTk2Nzg2LTgzODktNGEzYi05NmU0LTU5ODc4OTMxNTZiZQBGAAAAAADuF3VB4SlIT6v3u7na6JIHBwCfoOdZk3FLQau%2B3XsCiAazAAAAAAEPAACfoOdZk3FLQau%2B3XsCiAazAAEpvIT5AAA%3D&exvsurl=1&viewmodel=ReadMessageItem",
    "InferenceClassification": "Focused",
    "Body": {
        "ContentType": "HTML",
        "Content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nultra aneh\r\n</body>\r\n</html>\r\n"
    },
    "ToRecipients": [
        {
            "EmailAddress": {
                "Name": "jais anas",
                "Address": "jaisanas2@gmail.com"
            }
        }
    ],
    "CcRecipients": [],
    "BccRecipients": [],
    "ReplyTo": [],
    "Flag": {
        "FlagStatus": "NotFlagged"
    }
}

不幸的是,帖子只创建草稿不发送电子邮件。您可以查看"IsDraft": true的部分内容。 我的问题是如何获取没有商店消息的已发送商品的ID到草稿?我没有看到任何文档如何从已发送的电子邮件中获取ID here

1 个答案:

答案 0 :(得分:0)

  
    

我的问题是如何获取没有商店消息的已发送商品的ID到草稿

  

正如大卫在POST中所提到的,因为发送已完成异步,服务不会向您返回ID,因此您需要根据您在发送电子邮件中设置的ID进行搜索。在您的SearchKey示例中,您不发送只是创建项目的消息,例如您将其发布到Messages而不是/ email / sendmail。

我的建议是使用SearchKey设置InternetMessageId这是一个强类型属性。您需要确保在执行此操作时在属性值中使用唯一的Guid,否则如果客户端未设置唯一值,则会在电子邮件中破坏RFC。例如,发送消息并设置InternetMessageId(这对任何客户端来说都是有效的)

https://graph.microsoft.com/v1.0/me/sendMail

{
  "message": {
    "subject": "Meet for lunch?",
    "body": {
      "contentType": "Text",
      "content": "The new cafeteria is open."
    },
    "internetMessageId" : "7a2e515b-3052-4070-ac48-dac35624c613@mydomain.com",
    "toRecipients": [
      {
        "emailAddress": {
          "address": "gscales@mydomain.com"
        }
      }
    ]
  }
}

然后在您使用的已发送项目中找到该消息

https://graph.microsoft.com/v1.0/me/mailFolders/SentItems/messages?$filter internetMessageId eq '7a2e515b-3052-4070-ac48-dac35624c613@mydomain.com'

(我知道我正在使用Graph API,但它在另一个端点中的工作方式相同)