通过 Web 在 Office 365 中创建草稿邮件 API

Create Draft mail in Office 365 via Web API

我有一个带有 EF 的 Web API 后端,并使用 AzureAD 对我的 AngularJS.

中编写的 Web 应用程序的 (office365) 用户进行身份验证

现在我想在我的 Web 中创建草稿邮件 API 但我不知道从哪里开始。

我可以在 Web API 中调用 Office 365 邮件 API 吗? POST https://outlook.office365.com/api/{版本}/me/sendmail

但是我该如何传递身份验证令牌呢?

这是我现在使用的 Auth 配置,它适用于其他数据请求。

public static class Auth
{
    internal static void ConfigureCors(this IAppBuilder app)
    {
        // TODO: Configure to only allow ESS Web UI
        app.UseCors(CorsOptions.AllowAll);
    }

    internal static void ConfigureAuth(this IAppBuilder app)
    {
        app.UseWindowsAzureActiveDirectoryBearerAuthentication(
            new WindowsAzureActiveDirectoryBearerAuthenticationOptions
            {
                TokenValidationParameters = new TokenValidationParameters
                {
                    ValidAudience = Settings.Default.Audience
                },
                Tenant = Settings.Default.Tenant
            });
    }
}

谁有一些示例代码可以向 Office 365 发出正确的请求 API?谢谢!我是 Office 365 API 和这个网站的新手: https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations

我不太清楚如何处理这个..

您可以通过自己创建适当的 REST 请求(使用 HttpClient 或类似的东西)来执行此操作,或者您可以使用适用于 Office 365 API 的 .NET SDK。有一个 getting started tutorial that shows how to use the SDK. It retrieves mail rather than creates, but it should get you started. Creating a draft (with the SDK) is covered here.

对于身份验证,您需要获得一个 OAuth2 令牌,该令牌作为不记名令牌在 Authorization header 中传递。 Azure Active Directory 身份验证库可用于此目的。

如果您选择自己实现REST,请求格式涵盖here. There's an overview of getting started with raw REST here