问题
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