-2

I need to write a .NET Core console application which gets some emails from Office 365 account.

Is there any possibilities to get access to Office 365 API without any pop-ups and UI using email and password?

I tried a solution with registering an app in Azure Active Directory, but it isn't really suitable for my purposes, because a user, who logs in must be associated with a particular AAD account.

I found such question on Stuck Overflow, but all of them are related to old versions of API and old approaches.

I was looking for a solution for 4 days and read a plenty of documentation, but I'm still stuck.

Yulia
  • 102
  • 2
  • 5
  • 1
    This looks pretty good documentation with examples: [Get started with Office 365 Management APIs](https://learn.microsoft.com/en-us/office/office-365-management-api/get-started-with-office-365-management-apis) – Renatas M. Nov 30 '18 at 14:48
  • https://learn.microsoft.com/en-us/graph/overview –  Nov 30 '18 at 14:49
  • @Reniuz, this documentation covers an option with redirecting a user to the Azure AD website for obtaining authorization code. I can't use this approach – Yulia Nov 30 '18 at 15:14
  • You need to register your API in your Office 365 Azure AD and allow access to Graph API. From there, you can create and use application secret key to obtain the access token for the Graph API. – Dusan Nov 30 '18 at 15:25
  • @Dusan, but it'll work only for a user, who registered an app, am I right? And this user cannot use a personal account, only work/study – Yulia Nov 30 '18 at 15:36

1 Answers1

2

The following example is use the Exchange API - not Office 365 API.

This is an example of logging in to Office 365's Exchange server and sending off a calendar entry to an email address.

//Connect to exchange
var ewsProxy = new ExchangeService(ExchangeVersion.Exchange2013);
ewsProxy.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");

//Create the meeting
var meeting = new Appointment(ewsProxy);

ewsProxy.Credentials = new NetworkCredential(_Username, _Password);
meeting.RequiredAttendees.Add(_Recipient);

// Set the properties on the meeting object to create the meeting.
meeting.Subject = "Meeting";
meeting.Body = "Please go to the meeting.";
meeting.Start = DateTime.Now.AddHours(1);
meeting.End = DateTime.Now.AddHours(2);
meeting.Location = "Location";
meeting.ReminderMinutesBeforeStart = 60;

// Save the meeting to the Calendar folder and send the meeting request.
meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy); 

For more information, please see the following links:

Consume Office 365 REST API Without UI

Get Office 365 API access token without user interaction

Lina
  • 261
  • 1
  • 4