Outlook REST API SendMail - https://outlook.office.com/api/v



我正在开发一个应用程序,该应用程序使用 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,现在可以工作了。

最新更新