发送电子邮件时从Outlook REST API获取电子邮件ID [英] Getting the email id from the Outlook REST API when sending email

查看:295
本文介绍了发送电子邮件时从Outlook REST API获取电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Microsoft Rest API代表我们的用户发送电子邮件.当我创建消息作为草稿时,我会获得一个ID,该ID可在以后的请求中用于编辑,删除,查看完整的对话(发送后)等.

I am trying to use the Microsoft Rest API to send emails on behalf of our users. When I create a message as a draft, I get back an ID that I can use in future requests for editing, deleting, viewing the full conversation (after it is sent), etc.

我不想将其另存为草稿,因为我没有理由只想直接发送.发送后,我仍然想查看完整的对话.但是,如果我只是发送电子邮件(使用/sendmail端点),则不会获得该ID.反正有得到它吗?这是我的要求:

I do not want to save it as a draft since I have no reason to, I just want to send it directly. After it is sent, I would still like to view the full conversation. However, if I just send the email (using the /sendmail endpoint), I do not get that ID. Is there anyway to get it? Here is my request:

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

{
    "Message": {
        "Subject": "Test",
        "Importance": "Normal",
        "ToRecipients": [{
            "EmailAddress": {
                "Address": "<email>",
                "Name": "<name>"
            }
        }],
        "Sender": {
            "EmailAddress": {
                "Address": "<email",
                "Name": "<name>"
            }
        },
        "Body": {
            "ContentType": "HTML",
            "Content": "<html>\\n<head>\\n  <style>\\n    p { color: red; }\\n  </style> \\n</head>\\n<body>\\n  <p>Test</p>\\n</body>\\n</html>\\n"
        }
    },
    "SaveToSentItems": "true"
}

电子邮件发送的HTTP响应代码为202,但正文为空(无内容).

The HTTP response code is 202, the email sends, but the body is empty (no content, whatsoever).

我认为这无关紧要,因为我可以在Postman中重新创建它,但是我正在使用node-outlook包在Nodejs中运行它.

I don't think this matters, since I can recreate this in Postman, but I am running this in Nodejs using the node-outlook package.

推荐答案

通过REST和EWS提交的Exchange中的电子邮件已被提交进行传输,但是实际的发送和随后的保存都已完成.异步.这就是为什么您没有获取ID的原因.实际是将电子邮件写到已发送邮件文件夹而不是REST的人.

Emails in Exchange via REST and EWS are submitted for transport, but the actual send and subsequent save to the sent items folder are done async. This is why you don't get the id. Transport is who actually writes the email to the sent items folder, not REST.

如果在将项目保存到sendItems文件夹后确实需要查找该项目,请设置PR_SEARCH_KEY之类的内容,然后查看已发送项目文件夹并搜索该搜索键值.

If you really need to find the item after it has been saved to the sentItems folder, set something like the PR_SEARCH_KEY and then do a view of the sent items folder and seek to that search key value.

还请注意,当您保存草稿时,您返回的ID将与已发送的项目文件夹中的项目ID不同,因为文件夹ID是该项目ID的一部分,因此该ID不会无论如何都可以帮助您.

Also note when you save a draft, the id that you get back will be different than the id of the item in the sent items folder because the folder Id is part of the id of the item, so that id wouldn't help you anyways.

这篇关于发送电子邮件时从Outlook REST API获取电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆