Consume Office 365 REST API Without UI

前端 未结 3 657
半阙折子戏
半阙折子戏 2021-01-05 16:22

I need to push calendar entries in to a client\'s Outlook account. This is fairly straight forward with Exchange. You just authenticate with a user that has access, and then

3条回答
  •  伪装坚强ぢ
    2021-01-05 16:37

    The answer is simple. Use the Exchange API - not Office 365 API.

    I was confused because I assumed that Office 365 was a different entity to Exchange, but the Office 365 email server just is one giant Exchange server. Here's some sample code for good measure. This is an example of logging in to Office 365's Exchange server and sending off a calendar entry to an email address. Simple.

    I made a wild guess about the exchange Url and it was correct: https://outlook.office365.com/ews/exchange.asmx

        //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); 
    

提交回复
热议问题