18

We are developing a module with the main goal being to track and collect information about damage inspections (insurance market). Each case has a code (e.g. L000525). Each case could be managed by several people. All the emails related to a specific case include the case code in the subject.

What we want to do is to collect and show the incoming and sent emails related to each specific case.

The idea is that any user can open a "Case management" window, select an specific case, and then get all the related information (including the emails of course).

We have to find the emails into the the mailboxes of around 20 users. So the questions are:

  • Which is the better way to do this? Will it consume a lot of time and resources?

We are new in the Exchange world so we are thinking Exchange impersonation, but we are not sure at all. The module is developed in Silverlight 3, WCF, SQL Server + Exchange 2007.

Bernhard Hofmann
  • 10,321
  • 12
  • 59
  • 78

2 Answers2

61

If the credentials used to connect to EWS have rights to access a user's mailbox then you should be able to do something like this:

var service = new ExchangeService();
service.Credentials = new WebCredentials("user_with_access@example.com", "password");
service.AutodiscoverUrl("a_valid_user@example.com");

var userMailbox = new Mailbox("target_user@example.com");
var folderId = new FolderId(WellKnownFolderName.Inbox, userMailbox);

var itemView = new ItemView(20);   // page size
var userItems = service.FindItems(folderId, itemView);

foreach (var item in userItems)
{
    // do something with item (nb: it might not be a message)
}

That's it. Wow, my first SO answer!

smcintosh
  • 825
  • 7
  • 8
  • This definitely helped me. I needed to get a list of all appointments from shared calendars from a single login. Turns out this, alongside setting "Reviewer" permissions on each of the calendars for my login, was all I needed to do. – cmptrgeekken May 17 '13 at 20:20
  • In Exchange 2013 (Office 365), the user needs at least 'Full Details' permission. Limited or Availability Only will not work. – harsimranb Aug 28 '13 at 22:09
  • 1
    the class is called FolderId not FolderID, the rest worked just fine. thx! – Damian Vogel Sep 13 '13 at 13:13
  • Great! an example of how to do this for calendars (very similar) is http://www.independentsoft.de/exchangewebservices/tutorial-2.1/accesstoanothermailbox.html – Brent May 14 '14 at 17:04
  • Most examples I found used the default mailbox associated with the credentials used. Thanks! – Jett Oct 06 '14 at 06:24
  • 2
    For a guy who only ever gave one answer he sure made it a belter. – cms_mgr Mar 24 '15 at 13:41
  • @harsimranb Which permission is required to access other people's mailboxes. When I try it with Admin user I get `The SMTP address has no mailbox associated with it.` error. – kamaci May 28 '17 at 14:51
1

A full working example of what @smcintosh has done above is here: Office365 API - Admin accessing another users/room's calendar events. It is a full java class that should compile and run and accesses a room resource calendar. Good luck!

Community
  • 1
  • 1
Twelve24
  • 637
  • 7
  • 15