Reputation: 21
I have a requirement where I need to automate clients outlook inbox, where I need to read the emails and process it. Client belongs to different company and he has different outlook/office 365 subscription.
I was going through IAMP OAuth2 flow with C#. It speaks about adding Azure App Registrations, permissions etc.
My questions is, since my client is not using Azure and if i configure all app registrations/permissions in my azure instance, can I access his email inbox using IMAP OAuth2 flow using my Azure App or does client have to do something from his end?
Regards
Madhu
Upvotes: 0
Views: 102
Reputation: 15444
I agree with @Max, it is possible to access another tenant’s Outlook email inbox by configuring a multi-tenant app in Azure, but your client must explicitly consent to granting your app access to their data.
IMAP.AccessAsUser.All
l or Mail.Read
.When your client tries to use the app, they will authenticate via Azure AD. During this process, they will be prompted to consent to the permissions your app is requesting.
You can either use Office 365 Exchange Online API permissions or Microsoft Graph API permissions like below:
And retrieve the messages:
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "common";
var clientId = "ClientID";
var options = new InteractiveBrowserCredentialOptions
{
TenantId = tenantId,
ClientId = clientId,
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
RedirectUri = new Uri("http://localhost"),
};
var interactiveCredential = new InteractiveBrowserCredential(options);
var graphClient = new GraphServiceClient(interactiveCredential, scopes);
try
{
var messages = await graphClient.Users["UserID"].Messages.GetAsync(); ;
foreach (var message in messages.Value)
{
Console.WriteLine($"Subject: {message.Subject}");
}
}
catch (ODataError odataError)
{
Console.WriteLine(odataError.Error.Code);
Console.WriteLine(odataError.Error.Message);
}
Upvotes: 0