Microsoft Graph sendMail 不起作用并且 returns NULL

Microsoft Graph sendMail doesn't work and returns NULL

我正在尝试使用 MS Graph 1.0 发送 e-mails,但我没有得到任何结果或响应。 E-Mails 尚未发送并且 sendMail 方法不会 return 任何消息错误...它只显示 "null".

我的代码基于此示例 https://github.com/microsoftgraph/msgraph-sdk-javascript#post-and-patch 并且如下所示:

// Initialize Graph client
  const client = graph.Client.init({
    authProvider: (done) => {
      done(null, accessToken);
    }
  });

  try {
    // construct the email object
    var mail = {
        subject: "Microsoft Graph JavaScript Sample",
        toRecipients: [{
            emailAddress: {
                address: "mail@domain.com"
            }
        }],
        body: {
            content: "<h1>MicrosoftGraph JavaScript Sample</h1>Check out https://github.com/microsoftgraph/msgraph-sdk-javascript",
            contentType: "html"
        }
    };

    client
        .api('/me/sendMail')
        .post({message: mail}, (err, res) => {
            console.log("---> " + res);
        });

    console.log("Try ends");

  } catch (err) {
    parms.message = 'Error retrieving messages';
    parms.error = { status: `${err.code}: ${err.message}` };
    parms.debug = JSON.stringify(err.body, null, 2);
    res.render('error', parms);
  }

我猜 mail var 需要一个 header,但无论如何,API 应该 return 我的东西,对吧?而且,显然,电子邮件发送的问题是什么?

我终于将 rawResponse 添加到 .post 调用并查看错误日志...

client
  .api('/me/sendMail')
  .header("Content-type", "application/json")
  .post({message: mail}, (err, res, rawResponse) => {
      console.log(rawResponse);
      console.log(err);
});

...我发现我的身份验证令牌有问题。所以,我正确使用了 api,问题中的代码没问题。