Pergunta

I'm writing some code that does administrative tasks on an Exchange server, and I need to set a public folder's permissions, giving myself (that is, the mailbox/user that is connected to Exchange) permissions on a given folder.

The code for this is along these lines:

UserId userId = ???;
myFolder.Permissions.Add(userId, FolderPermissionLevel.Owner);
myFolder.Update();

This code would work fine (and there's no problem with me having permissions to grant myself permissions, since I'm in the Public Folder Management AD group), but the problem is that I don't have UserId object that represents the current user. I don't even have a primarySmtpAddress, which is another way to get a UserId. All I know is that I'm in the context of a user that has permissions to a mailbox - it might be the current Windows user, it might just be a NetworkCredential that was passed to my library.

Is there a way in EWS to get the current user, or at least the current user's SMTP address? I looked in the ExchangeService class but couldn't find anything to that effect.

Foi útil?

Solução

If you have the NetworkCredential you can bind to AD and use the GetObject to get the IADsUser. From there you can get the email address. Then you can use:

UserIdType user = new UserIdType(); user.PrimarySmtpAddress = "user3@example.com.com";

to set your permissionset userid:

http://msdn.microsoft.com/en-us/library/bb856574(v=exchg.80).aspx

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top