Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exchange Web Services Managed API: Accessing other users items

Is it possibly to access the folders and items of other Exchange accounts other than the one of the logged in user?

Can I do this via Exchange Web Services Managed API?

like image 235
Luke Avatar asked Sep 24 '10 12:09

Luke


People also ask

What is Microsoft Exchange Web Services Managed API?

Microsoft Exchange Web Services (EWS) is a native API built by Microsoft that allows server/client applications to integrate with Exchange Servers and Office 365. Connecting Salesloft to Office 365 or Exchange Server through Microsoft's EWS API allows access to calendars and emails.

Does Exchange Web Services support modern authentication?

See Upcoming changes to Exchange Web Services (EWS) API for Office 365. Many applications have successfully moved to Graph, but for those applications that have not, it's noteworthy that EWS already fully supports Modern authentication.

How do I add a reference to Microsoft Exchange webservices?

By default, the files are installed in C:\Program Files\Microsoft\Exchange\Web Services\2.0\ , but you can store the files anywhere on your computer. In the Solution Explorer pane in Visual Studio, select References, and then choose Add Reference.


2 Answers

Yes it is possible, but you should know the password of the other user or grab in some ways this credentials (NetworkCredential object). The typical first lines of you code could be

ExchangeService myService = new ExchangeService (ExchangeVersion.Exchange2007_SP1);
myService.Credentials = new NetworkCredential ("[email protected]", "P@ssword00");

so you can access Exchange Server Web Services with the account which is other as the current user. See ExchangeService object description for more information.

If you are an admin you can make user impersonation by SMTP address.

like image 102
Oleg Avatar answered Oct 13 '22 18:10

Oleg


Knowing the password is wrong and using impersonation (these days) is wrong.

Here's how you do it.

        ExchangeService _service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        //CREDENTIALS OF AN ACCOUNT WHICH HAS READ ACCESS TO THE CALENDAR YOU NEED
        _service.Credentials = new WebCredentials(username, password);
        _service.Url = new Uri(serviceURL);

        SearchFilter.SearchFilterCollection searchFilter = new SearchFilter.SearchFilterCollection();
        searchFilter.Add(new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, DateTime.Now.AddDays(-1)));
        searchFilter.Add(new SearchFilter.IsLessThanOrEqualTo(AppointmentSchema.Start, DateTime.Now.AddDays(2)));
        ItemView view = new ItemView(50);
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.AppointmentType, AppointmentSchema.End);

        //THIS NEXT LINE!!!
        var calendarSearch = new FolderId(WellKnownFolderName.Calendar, new Mailbox("[email protected]"));
        var appointments = _service.FindItems(calendarSearch, searchFilter, view);
like image 37
Preston Avatar answered Oct 13 '22 19:10

Preston