Create Draft mail in Office 365 via Web API

与世无争的帅哥 提交于 2019-12-24 13:26:17

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/31289809/create-draft-mail-in-office-365-via-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!