通过Web API在Office 365中创建草稿邮件 [英] Create Draft mail in Office 365 via Web API

查看:112
本文介绍了通过Web API在Office 365中创建草稿邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用EF的Web API后端,并使用AzureAD来验证我(office365)用AngularJS编写的Web应用程序的用户.

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

我可以仅在Web API中调用Office 365邮件API吗? POST https://outlook.office365.com/api/ {version}/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或类似方法),也可以将.NET SDK用于Office 365蜜蜂.有一个入门教程,其中显示了如何使用SDK.它检索邮件而不是创建邮件,但是它应该可以帮助您入门. 此处

对于身份验证,您需要获取一个OAuth2令牌,该令牌将作为承载令牌在Authorization标头中传递. Azure Active Directory身份验证库可用于此目的.

如果您选择自己实施REST,则将覆盖请求的格式此处.

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.

Now I want to create a draft mail in my Web API but I don't know where to start.

Can I just call the Office 365 mail API in my Web API? 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.

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? 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

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. There's a 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.

For authentication you need to get an OAuth2 token, which gets passed in the Authorization header as a bearer token. The Azure Active Directory Authentication Library can be used for this.

If you choose to implement the REST yourself, the format of the request is covered here. There's an overview of getting started with raw REST here.

这篇关于通过Web API在Office 365中创建草稿邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆