Office 365 Exchange Mailbox Properties - c#

I would like to know how to access a set of given mailboxes and get various properties on those mailboxes. Specifically I would like to iterate through a list of email addresses, and spit out the type of mailbox (ie: room mailbox, user mailbox , etc.)and who and what type of access users have. I've been looking at url below, but cant find much on this type of thing.
https://code.msdn.microsoft.com/Office365/
An code samples would be greatly appreciated.
Pseudo Code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
var MyMailboxes = service.getMailboxes(MyListofMailboxes);
foreach(var mailbox in MyMailboxes)
{
Console.WriteLine("MailboxType: {0}" + mailbox.MailboxType);
foreach(var userAccess in mailbox.UserAccess)
{
Console.Writeline("User: {0}, Access Level: {1}", userAccess.user, userAccess.AccessLevel);
}
}

You need to use Remote Powershell to do that see https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx. You can the use Get-Mailbox, Get-MailboxPermission and Get-MailboxFolderPermissions . EWS is only useful if you want to access the Mailbox content for Admin tasks you should use Remote Powershell.
Cheers
Glen

Related

VSTO - How get account email address from Outlook.Store entity

Some time ago to get Outlook accounts and account info (e.g. Email address, SMTP address) i was use Outlook.Accounts entity, but Outlook.Accounts caches data and doesn't support events like Add/Remove. Here I was offered to switch to Outlook.Stores (Outlook.Store) entity, but I don’t understand how I can get the Email address from Outlook.Store at least.
If the store is associated with any account configured in Outlook you can use the following code which iterates over all accounts configured and finds the required one where you may ask for an email address:
Outlook.Account GetAccountForFolder(Outlook.Folder folder)
{
// Obtain the store on which the folder resides.
Outlook.Store store = folder.Store;
// Enumerate the accounts defined for the session.
foreach (Outlook.Account account in Application.Session.Accounts)
{
// Match the DefaultStore.StoreID of the account
// with the Store.StoreID for the currect folder.
if (account.DeliveryStore.StoreID == store.StoreID)
{
// Return the account whose default delivery store
// matches the store of the given folder.
return account;
}
}
// No account matches, so return null.
return null;
}
The Account.SmtpAddress property returns a string representing the Simple Mail Transfer Protocol (SMTP) address for the Account. The purpose of SmtpAddress and Account.UserName is to provide an account-based context to determine identity. If the account does not have an SMTP address, SmtpAddress returns an empty string.
Generally, stores do not have an intrinsic identity - imagine a standalone PST store: there is no user identity associated with it. Or you can have multiple POP3/SMTP accounts delivering to the same PST store - you now have multiple identities associated with the PST store.
Or imagine having a PF store - it is accessible to multiple users without having its own identity.
Only Exchange stores have a notion of an owner. You can go from an Exchange store to an email account by looping through the Namespace.Accounts collection and comparing (using Namespace.CompareEntryIDs) the entry id of your store in question and the store exposed by the Account.DeliveryStore property.
If using Redemption is an option (I am its author), it exposes the Exchange mailbox owner directly through the RDOExchangeMailboxStore.Owner property (returns RDOAddressEntry object).

Get calendars of office365 email without authentication

I want to get list of events of particular users lets say user#company1.com , user#company2.com which uses office365 accounts.
I need to retrive user#company2.com calendar with out login. My application will be like listing my available timings for my clients , so that they can select my free time and will schedule meeting with me. I need to filter the already scheduled events from my list... Is there any example code for getting calendar events without login??
I tried office365 multi-tenant application which will gives sample code for getting calendar events only after login. I need it with out authentication. Please help me on this.
Trying to access the O365 information without authentication is impossible , either user authentication or app authentication will be required . In your scenario ,you may need app authentication . You could try to build Daemon or Service Apps using client credential grant flow as described in this blog, the service app that requires admin consent, but is authorized to access any mailbox/calendar information in your Office 365 tenant.
Another choice is to use EWS Managed API, you could get free/busy information of a user and suggested meeting times by using the EWS Managed API :
https://msdn.microsoft.com/en-us/library/office/dn643673(v=exchg.150).aspx
And an existing Office add-in support on Outlook:
https://findtime.microsoft.com/
Finally I tried to use the free/busy code. My code is as follows... I am following this procedure but I don't know if it is correct or not. I have a Microsoft Office 365 account, and by passing credentials silently, I am creating Exchange Server service. After that i am passing different domain attendee information as ORGANIZER and REQUIRED as follows. But it is returning all values not skipping any scheduled meetings for those users.
Lets assume user1#domain.com is ORGANIZER and user2#anotherdomain.com is REQUIRED for meeting . User1 have meeting scheduled at 7:00-7:30pm on daily basis but when I executed the following script it shows me 7:00-7:30pm as available for meeting. It supposed to block that time.
Can you suggest some changes to code and am I proceeding in the correct way?
private static void GetSuggestedMeetingTimes(ExchangeService service)
{
List<AttendeeInfo> attendees = new List<AttendeeInfo>();
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "user1#mydomain.com",
AttendeeType = MeetingAttendeeType.Organizer
});
attendees.Add(new AttendeeInfo()
{
SmtpAddress = "user2#anotherdomain.com",
AttendeeType = MeetingAttendeeType.Required
});
// Specify options to request free/busy information and suggested meeting times.
AvailabilityOptions availabilityOptions = new AvailabilityOptions();
availabilityOptions.GoodSuggestionThreshold = 49;
availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
availabilityOptions.MaximumSuggestionsPerDay = 40;
// Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
availabilityOptions.MeetingDuration = 30;
availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good;
availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;
// Return free/busy information and a set of suggested meeting times.
// This method results in a GetUserAvailabilityRequest call to EWS.
GetUserAvailabilityResults results = service.GetUserAvailability(attendees,
availabilityOptions.DetailedSuggestionsWindow,
AvailabilityData.FreeBusyAndSuggestions,
availabilityOptions);
// Display suggested meeting times.
Console.WriteLine("Availability for {0} and {1}", attendees[0].SmtpAddress, attendees[1].SmtpAddress);
Console.WriteLine();
foreach (Suggestion suggestion in results.Suggestions)
{
Console.WriteLine("Suggested date: {0}\n", suggestion.Date.ToShortDateString());
Console.WriteLine("Suggested meeting times:\n");
foreach (TimeSuggestion timeSuggestion in suggestion.TimeSuggestions)
{
Console.WriteLine("\t{0} - {1}\n",
timeSuggestion.MeetingTime.ToShortTimeString(),
timeSuggestion.MeetingTime.Add(TimeSpan.FromMinutes(availabilityOptions.MeetingDuration)).ToShortTimeString());
}
}
int i = 0;
// Display free/busy times.
foreach (AttendeeAvailability availability in results.AttendeesAvailability)
{
Console.WriteLine("Availability information for {0}:\n", attendees[i].SmtpAddress);
foreach (CalendarEvent calEvent in availability.CalendarEvents)
{
Console.WriteLine("\tBusy from {0} to {1} \n", calEvent.StartTime.ToString(), calEvent.EndTime.ToString());
}
i++;
}

EWS: Mailbox address from a Calendar FolderId, is it possible?

I have stored Calendar FolderIds in order report on calendar events which a user has access to. I'm using Exchange Web Services via c# (using Microsoft.Exchange.WebServices)
These calendars can be associated with the authenticated user's mailbox, a shared mailbox, an impersonated|delegated mailbox, or a public mailbox. And now I'd like to go from the FolderId to the mailbox address.
Ideally there'd be a function to
string address = getMailboxAddress(new FolderId("AAJk...AA="));
If you have the FolderId what you have is the EWS version of this https://msdn.microsoft.com/en-us/library/ee217297(v=exchg.80).aspx which means with the data you have doesn't contain the Email Address. You would be better at the time you store the CalendarId store the Email address its associated with.
You can try using ConvertId with a generic non resolvable email Address this should return the EmailAddress the folder belongs (won't work for Public Folder) to eg
AlternateId aiAlternateid = new AlternateId(IdFormat.EwsId, SharedFoder.Id.UniqueId, "mailbox#domain.com");
AlternateIdBase aiResponse = service.ConvertId(aiAlternateid, IdFormat.EwsId);
Console.WriteLine(((AlternateId)aiResponse).Mailbox);
Cheers
Glen

MS Exchange server cloud, getting all items in a different

I am trying to figure out how to access all items from a 'room' account.
Is it possible to somehow access the data from the room when that user isn't a real user?
I can get all rooms but the question is how to query the finditems using the room account.
You will need to authenticate as some user with a Mailbox and then grant that user access to the Room's Calendar (or the whole mailbox using Add-MailboxPermissions) or make it a delegate. Then you can just use the FolderId overload to specify you want to query that Room's Calendar folder eg
FolderId RoomMailboxCalendarFolderId = new FolderId(WellKnownFolderName.Calendar, "room#domain.com");
CalendarView cvCalView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(31));
FindItemsResults<Appointment> appointments = service.FindAppointments(RoomMailboxCalendarFolderId, cvCalView);
Cheers
Glen

Accessing 2nd exchange inbox from Outlook 2013 using VSTO

Getting default inbox works like the following:
_outlookNameSpace = this.Application.GetNamespace("MAPI");
_inbox = _outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Now on the same lines, how do get the inbox for the other exchange account say "abc#corp.com" ?
Thanks in advance.
Assuming the second mailbox is already in the profile, you need to find the appropriate account in the Namespace.Stores collection and call Store.GetDefaultFolder.
Otherwise you can call Namespace.GetSharedDefaultFolder.
I have a similar situation, where the 2nd account is identified by its .DisplayName property, which can be set in Account Setup. To find the Account, use:
var account = Globals.Addin.Application.GetNamespace("MAPI")
.Accounts.Cast<Account>()
.FirstOrDefault(a => a.DisplayName == "TargetDisplayName");
Then use Account.DeliveryStore to get access to the store and find the folder. .GetDefaultFolder gives you the folder:
DraftsFolder = (Folder) account.DeliveryStore.GetDefaultFolder(OlDefaultFolders.olFolderDrafts);

Categories