简体   繁体   English

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

[英]Create Draft mail in Office 365 via Web API

I have a Web API backend with EF and use AzureAD to authenticate my (office365)users of the web application that is written in AngularJS. 我有一个使用EF的Web API后端,并使用AzureAD来验证我(office365)用AngularJS编写的Web应用程序的用户。

Now I want to create a draft mail in my Web API but I don't know where to start. 现在,我想在Web API中创建邮件草稿,但是我不知道从哪里开始。

Can I just call the Office 365 mail API in my Web API? 我可以仅在Web API中调用Office 365邮件API吗? POST https://outlook.office365.com/api/ {version}/me/sendmail POST https://outlook.office365.com/api/ {version} / me / sendmail

But how do I pass the authentication token with it? 但是,我该如何传递身份验证令牌?

Here is the Auth config that I use now and it works for other data requests. 这是我现在使用的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
            });
    }
}

Any one how has some sample code to make the correct request to the Office 365 API? 有人如何向Office 365 API发出正确的请求的示例代码? Thank you! 谢谢! I'm new to the Office 365 API and this website: https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations 我是Office 365 API和这个网站的新手: https : //msdn.microsoft.com/zh-cn/office/office365/api/mail-rest-operations

is not so clear for me to know how to handle this.. 我不太清楚如何处理此问题。

You can do this by creating the proper REST request yourself (using HttpClient or something similar), or you can use the .NET SDK for the Office 365 APIs. 您可以自己创建适当的REST请求(使用HttpClient或类似方法),也可以将.NET SDK用于Office 365 API。 There's a getting started tutorial that shows how to use the SDK. 有一个入门教程 ,显示了如何使用SDK。 It retrieves mail rather than creates, but it should get you started. 它检索邮件而不是创建邮件,但是应该可以帮助您入门。 Creating a draft (with the SDK) is covered here . 在此处介绍了使用SDK创建草稿的过程。

For authentication you need to get an OAuth2 token, which gets passed in the Authorization header as a bearer token. 为了进行身份验证,您需要获取OAuth2令牌,该令牌会作为承载令牌在Authorization标头中传递。 The Azure Active Directory Authentication Library can be used for this. Azure Active Directory身份验证库可用于此目的。

If you choose to implement the REST yourself, the format of the request is covered here . 如果您选择自己实施REST,则此处将介绍请求的格式。 There's an overview of getting started with raw REST here . 还有的入门生REST的概述这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM