Accessing 2nd exchange inbox from Outlook 2013 using VSTO - c#

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

Related

Why is my List.GetUserEffectivePermissions() method not working?

I'm developing a process in C# with the SharePoint 2013 Client Side Object Model. I need to retrieve the SharePoint List Permissions of a given user, that will be different than the user that is executing the code.
using SP = Microsoft.SharePoint.Client;
SP.ClientContext SpContext = new SP.ClientContext("SITEURL");
SP.Web SiteWeb = SpContext.Web;
SP.List Lst = SpContext.Web.Lists.GetByTitle("LIST");
var ClientUserEffPerms = Lst.GetUserEffectivePermissions(#"<domain>\<username>");
SpContext.Load(SiteWeb, S => S.EffectiveBasePermissions);
SpContext.Load(Lst, L => L.EffectiveBasePermissions);
SpContext.ExecuteQuery();
After this code executes, the ClientUserEffPerms.Value (BasePermissions) object does not represent the permissions of the given user correctly. The object isn't null, but it represents the user as having no permissions. The user has at minimum view and edit permissions and I can confirm this by viewing/editing List Items using the web browser as this user.
The code executing user has permission to enumerate permissions at both the Web and List level. I've confirmed this with the code below, both booleans resolve to true.
bool SvcUserHasSiteEnumPermsPerm = SiteWeb.EffectiveBasePermissions.Has(SP.PermissionKind.EnumeratePermissions);
bool SvcUserHasListEnumPermsPerm = Lst.EffectiveBasePermissions.Has(SP.PermissionKind.EnumeratePermissions);
Can anyone help me determine what is wrong with my GetUserEffectivePermissions() method?
When you call GetUserEffectivePermissions you need to pass in the full claims token version of the login name, which looks something like this:
i:0#.w|domain\user
You can get this by loading the LoginName property on a user object:
clientContext.Load(clientContext.Web.CurrentUser, i => i.LoginName);
clientContext.ExecuteQuery();
Of course, that's for the current user, so you'll need to acquire the user you actually want first.

Office 365 Exchange Mailbox Properties

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

Query a user's Language on Exchange 2003 using WebDAV

How can I programatically query a user's Language/Locale/Region from Exchange 2003?
I'm using Independentsoft's Exchange WebDAV api. I'm trying to get a method signature like:
public string GetUsersLanguage(string username, string password){
//magic
//return fr-FR, or en-US, or nl-NL, etc
}
Exchange 2003 will configure the default folders (Inbox, Calendar, etc) to match the user's locale the first time the mailbox is accessed. So Inbox becomes Postvak IN for Dutch. I'd prefer not to inspect the top level folders and match that against a lookup table; is there another way?
The WebDAV api has a property getcontentlanguage that looks like it should contain the associated language for a mailbox (or at least a top level folder like Inbox), but whenever I query for that field Exchange returns a 404:
I was able to get something close, but not exactly what I'm looking for. Exchange 2003 OWA has a property spellingdictionarylanguage that could contain a close approximation to the user's culture. I say could becuase this field if only set if the user has logged into OWA Premium (via IE in compatibility mode) and explicitly set the Spelling Dictionary.
Resource resource = new Resource(session);
var allProps = resource.GetProperties();
Console.WriteLine(
"Culture (Best Guess via Spelling Langauge): " +
allProps
.Where(x => x.Name == "spellingdictionarylanguage")
.Select(x => x.Value)
.FirstOrDefault() ?? "");
Hopefully there is still a better way to do this.

Create an outlook link from an item

I'm using Microsoft.Exchange.WebServices to work with some public folders and their items.
I would like to create a View item link to a specific item (Microsoft.Exchange.WebServices.Data.Item), but I can't figure out how to get it's path.
something like:
var theLink =
string.Format(#"Click here", item.XXXX);
Any suggestions?
It seems to not be possible anymore to due security.
Instead I created a link to Outlook Web Access instead.

EWS FolderPermission Add

How do you add multiple user folder permissions to a single folder in EWS? Without them being reset? So if i wanted to give usera#domain.com and userb#domain.com permissions to one folder at once?
UserId user = new UserId();
user.PrimarySmtpAddress ="userabc#domain.com";
FolderPermission fldperm = new FolderPermission(user, FolderPermissionLevel.Editor);
strfolder.Permissions.Add(fldperm);
strfolder.Update();
Can you not use the FolderPermissionCollection. Add all permissions to that collection then use the AddRange property to add the FolderPermissionCollection.
Thanks
Niall

Categories