Outlook REST API SendMail - https://outlook.office.com/api/v2.0/me/sendmail 的 Http 失败响应:401 未经授权
Outlook REST API SendMail - Http failure response for https://outlook.office.com/api/v2.0/me/sendmail: 401 Unauthorized
我正在开发一个应用程序,该应用程序使用 msgraph v.1.0 生成的令牌通过 outlook api v2.0 发送电子邮件。它一直工作到几周前(据我所知),但自上周三以来我尝试了它并且它不工作(不发送电子邮件)!我以为这是我的代码,但我将它反转为我以前的代码,但我仍然收到此错误:
我已经在 Microsoft 开发者网站上注册了我的应用程序,并获得了 Mail.Send 许可,然后返回那里进行确认。
我的应用程序还访问 SharePoint,它工作正常。当我登录时,我打印我的令牌,它看起来很好。之前都是发邮件。。不知道怎么回事。
"headers": {
"normalizedNames": {},
"lazyUpdate": null
},
"status": 401,
"statusText": "Unauthorized",
"url": "https://outlook.office.com/api/v2.0/me/sendmail",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure response for https://outlook.office.com/api/v2.0/me/sendmail: 401 Unauthorized",
"error": null
}
我用来发送电子邮件的代码是:
private serverUrl =
"https://outlook.office.com/api/v2.0/me/sendmail";
constructor(private
http: HttpClient) {}
postData(data:
any, token:
any) {
let options =
this.createRequestOptions(token);
return this.http.post(this.serverUrl,
data, { headers:
options })
.map(res
=> res);
}
private createRequestOptions(token:
any) {
let headers =
new HttpHeaders({
"Authorization":
"Bearer " +
token,
"Content-Type":
"application/json"
});
return headers;
}
我正在传递值:
this.mailService
.postData(this.data,
this.token)
.subscribe(
() => {
dialogs.alert("Email sent. Thank you!").then(function () {
let page =
topmost().currentPage;
page.modal.closeModal();
});
},
(e) => {
console.log(e);
alert({
message: "An error occurred while sending your contact helpdesk.",
okButtonText:
"OK"
});
});
有人遇到过这个问题吗?
我通过更改我用来发送电子邮件的 API 解决了我的问题。我没有使用 Outlook API,而是改为使用 MSGRAPH,所以现在我的变量 serverUrl 是 https://graph.microsoft.com/v1.0/me/sendmail,现在可以使用了。
我正在开发一个应用程序,该应用程序使用 msgraph v.1.0 生成的令牌通过 outlook api v2.0 发送电子邮件。它一直工作到几周前(据我所知),但自上周三以来我尝试了它并且它不工作(不发送电子邮件)!我以为这是我的代码,但我将它反转为我以前的代码,但我仍然收到此错误:
我已经在 Microsoft 开发者网站上注册了我的应用程序,并获得了 Mail.Send 许可,然后返回那里进行确认。 我的应用程序还访问 SharePoint,它工作正常。当我登录时,我打印我的令牌,它看起来很好。之前都是发邮件。。不知道怎么回事。
"headers": {
"normalizedNames": {},
"lazyUpdate": null
},
"status": 401,
"statusText": "Unauthorized",
"url": "https://outlook.office.com/api/v2.0/me/sendmail",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure response for https://outlook.office.com/api/v2.0/me/sendmail: 401 Unauthorized",
"error": null
}
我用来发送电子邮件的代码是:
private serverUrl =
"https://outlook.office.com/api/v2.0/me/sendmail";
constructor(private
http: HttpClient) {}
postData(data:
any, token:
any) {
let options =
this.createRequestOptions(token);
return this.http.post(this.serverUrl,
data, { headers:
options })
.map(res
=> res);
}
private createRequestOptions(token:
any) {
let headers =
new HttpHeaders({
"Authorization":
"Bearer " +
token,
"Content-Type":
"application/json"
});
return headers;
}
我正在传递值:
this.mailService
.postData(this.data,
this.token)
.subscribe(
() => {
dialogs.alert("Email sent. Thank you!").then(function () {
let page =
topmost().currentPage;
page.modal.closeModal();
});
},
(e) => {
console.log(e);
alert({
message: "An error occurred while sending your contact helpdesk.",
okButtonText:
"OK"
});
});
有人遇到过这个问题吗?
我通过更改我用来发送电子邮件的 API 解决了我的问题。我没有使用 Outlook API,而是改为使用 MSGRAPH,所以现在我的变量 serverUrl 是 https://graph.microsoft.com/v1.0/me/sendmail,现在可以使用了。