我们的应用程序具有一项功能,允许用户使用Outlook Rest Api直接从应用程序中发送电子邮件。我们创建草稿,可选择添加附件,然后发送电子邮件。这是使用RestSharp在C#中完成的。
我们的一些用户在创建草稿时遇到了问题。我无法破译错误消息的真正含义,如果正确的答案只是重试。 (有些用户再次手动尝试,它似乎连续多次失败)。然后,这些用户将看到稍后发送的成功电子邮件。
供参考,api端点为:https://outlook.office.com/api/v2.0/me/messages,参考文档位于:https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations#CreateNewDraft
样本休息响应:
{
"Request": {
"AlwaysMultipartFormData": false,
"JsonSerializer": {
"ContentType": "application/json"
},
"XmlSerializer": {
"ContentType": "text/xml"
},
"UseDefaultCredentials": false,
"Parameters": [
{
"Name": "Authorization",
"Value": "Bearer [[REMOVED]]",
"Type": 3
},
{
"Name": "Content-Type",
"Value": "application/json; charset=utf-8",
"Type": 3
},
{
"Name": "application/json",
"Value": "[[MIME MESSAGE]]",
"Type": 4
},
{
"Name": "Accept",
"Value": "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml",
"Type": 3
}
],
"Files": [],
"Method": 1,
"Resource": "api/v2.0/me/messages",
"RequestFormat": 1,
"OnBeforeDeserialization": {
"Delegate": {},
"method0": {
"Name": "<.ctor>b__0",
"AssemblyName": "RestSharp, Version=105.2.3.0, Culture=neutral, PublicKeyToken=null",
"ClassName": "RestSharp.RestRequest",
"Signature": "Void <.ctor>b__0(RestSharp.IRestResponse)",
"Signature2": "System.Void <.ctor>b__0(RestSharp.IRestResponse)",
"MemberType": 8,
"GenericArguments": null
}
},
"Timeout": 0,
"ReadWriteTimeout": 0,
"Attempts": 1
},
"ContentType": "",
"ContentLength": 0,
"ContentEncoding": "",
"Content": "",
"StatusCode": 555,
"StatusDescription": "Routing Failure",
"RawBytes": "",
"ResponseUri": "https://outlook.office.com/api/v2.0/me/messages",
"Server": "",
"Cookies": [
{
"Comment": "",
"Discard": false,
"Domain": "outlook.office.com",
"Expired": false,
"Expires": "2019-01-18T04:09:17+00:00",
"HttpOnly": true,
"Name": "exchangecookie",
"Path": "/",
"Port": "",
"Secure": false,
"TimeStamp": "2018-01-18T04:09:17.2631733+00:00",
"Value": "3b0a8015b9e24496bf28f9c6010e022a",
"Version": 0
},
{
"Comment": "",
"Discard": false,
"Domain": "outlook.office.com",
"Expired": false,
"Expires": "2018-01-18T04:24:17+00:00",
"HttpOnly": false,
"Name": "X-RouteRefreshCookie",
"Path": "/",
"Port": "",
"Secure": false,
"TimeStamp": "2018-01-18T04:09:17.2631733+00:00",
"Value": "zoHNz87H0s/O0s7Hq8/Lxc/Gxc7IgbKot6+tz8u8vs/Py8mBqoGwlpvFzZrOnsybzJvSzsqcx9LLy8zO0seempzSzsqdy53MyJyZz83N2svPycfIyMmanM3Syp6dndLLzMfJ0p6cy83SycqdnMjNy52Zms+dwruei56dnoyauIqWm8XPm5nPzM/KmdKbz8eb0svPz8fSncbOz9LPmsybzZzNzcbPx5vay8/Jx8jIyZqczdLKnp2d0svMx8nSnpzLzdLJyp2cyM3LnZmaz53ay8+RnpKPjZvNz9GPjZCb0ZCKi5OQkJTRnJCS2svPz7/OzM7Jz8jNzc7KyMzHzMzLyMc=",
"Version": 0
}
],
"Headers": [
{
"Name": "Set-Cookie",
"Value": "exchangecookie=3b0a8015b9e24496bf28f9c6010e022a; expires=Fri, 18-Jan-2019 04:09:17 GMT; path=/; HttpOnly,X-RouteRefreshCookie=zoHNz87H0s/O0s7Hq8/Lxc/Gxc7Igayxzq+tzsi8vs/PzsyBqoGwlpvFzZrOnsybzJvSzsqcx9LLy8zO0seempzSzsqdy53MyJyZz83N2svPycfIyMmanM3Syp6dndLLzMfJ0p6cy83SycqdnMjNy52Zms+dwruei56dnoyauIqWm8XPm5nPzM/KmdKbz8eb0svPz8fSncbOz9LPmsybzZzNzcbPx5vay8/Jx8jIyZqczdLKnp2d0svMx8nSnpzLzdLJyp2cyM3LnZmaz53ay8+RnpKPjZvNz9GPjZCb0ZCKi5OQkJTRnJCS2svPz7/OzM7Jz8jNzc7KyMzHzMzLyMc=; expires=Thu, 18-Jan-2018 04:24:17 GMT; path=/,X-RouteRefreshCookie=zoHNz87H0s/O0s7Hq8/Lxc/Gxc7IgbKot6+tz8u8vs/Py8mBqoGwlpvFzZrOnsybzJvSzsqcx9LLy8zO0seempzSzsqdy53MyJyZz83N2svPycfIyMmanM3Syp6dndLLzMfJ0p6cy83SycqdnMjNy52Zms+dwruei56dnoyauIqWm8XPm5nPzM/KmdKbz8eb0svPz8fSncbOz9LPmsybzZzNzcbPx5vay8/Jx8jIyZqczdLKnp2d0svMx8nSnpzLzdLJyp2cyM3LnZmaz53ay8+RnpKPjZvNz9GPjZCb0ZCKi5OQkJTRnJCS2svPz7/OzM7Jz8jNzc7KyMzHzMzLyMc=; expires=Thu, 18-Jan-2018 04:24:17 GMT; path=/",
"Type": 3
},
{
"Name": "request-id",
"Value": "ab8da322-62ac-4c32-b92b-accd590d7aaf",
"Type": 3
},
{
"Name": "X-CalculatedFETarget",
"Value": "SN1PR17CU001.internal.outlook.com",
"Type": 3
},
{
"Name": "X-BackEndHttpStatus",
"Value": "555,555",
"Type": 3
},
{
"Name": "X-FEProxyInfo",
"Value": "SN1PR17CA0013.NAMPRD17.PROD.OUTLOOK.COM",
"Type": 3
},
{
"Name": "X-CalculatedBETarget",
"Value": "SN1PR20MB0286.namprd20.prod.outlook.com",
"Type": 3
},
{
"Name": "x-ms-appId",
"Value": "8410d572-e055-48e5-b2c7-869538daf671",
"Type": 3
},
{
"Name": "X-BEServerRoutingError",
"Value": "Mailbox database change detected; moved from database 0fd6794b-0d64-4c64-be98-dc8157675f93 to 0df0305f-d08d-4008-b910-0e3d2c22908d",
"Type": 3
},
{
"Name": "X-DiagInfo",
"Value": "SN1PR20MB0286",
"Type": 3
},
{
"Name": "X-BEServer",
"Value": "SN1PR20MB0286",
"Type": 3
},
{
"Name": "X-FEServer",
"Value": "SN1PR17CA0013,MWHPR04CA0046",
"Type": 3
},
{
"Name": "X-Powered-By",
"Value": "ASP.NET",
"Type": 3
},
{
"Name": "X-MSEdge-Ref",
"Value": "Ref A: A07C0D2FC267430AA8A2AEEEA095E277 Ref B: BAYEDGE0211 Ref C: 2018-01-18T04:09:17Z",
"Type": 3
},
{
"Name": "Date",
"Value": "Thu, 18 Jan 2018 04:09:16 GMT",
"Type": 3
},
{
"Name": "Content-Length",
"Value": "0",
"Type": 3
}
],
"ResponseStatus": 1
}
注意:我已删除了一些详细信息,例如邮件本身和不记名令牌。如果需要进行调试,我可以再次混淆并包含这些信息。
更新:似乎错误代码已更改为503 Service Unavailable而不是555 Routing Failure,但细节似乎相同。关键响应头是&#34; X-BEServerRoutingError&#34;包含&#34;检测到邮箱数据库更改的值;从数据库[guid]移到[guid]&#34;。基于此SO问题的响应:Office365 API Error "Mailbox database change detected;",这似乎是一个已知的瞬态问题,解决方案只是重试。似乎没有任何关于重试次数或类似内容的指导。仍在寻找有适当指导的答案。
答案 0 :(得分:1)
与Microsoft进行长时间的支持票交谈后,他们的指导是添加重试策略。
上面的示例没有显示它,但是通常有一个标题为“ X-Retry-After”的标头,该标头具有一个代表分钟的整数值。如果值为0,则表示立即重试。
实施重试政策后,大约一个半星期以来我们再也没有看到错误。