Getting the User Settings from Exchange On-Line

Here it is a sample in order to get some Keys and Values relative to the Exchange Server User Settings

public void GetBindingAndKeys()
{
try
{
	//Create Service
	ExchangeService service = new
		ExchangeService(ExchangeVersion.Exchange2010_SP1)
	{ /*Assign Credentials*/
		Credentials = new
			WebCredentials("Your-Mail", "Your-Password")
	};
	// Create an instance of the AutodiscoverService.
	AutodiscoverService ads = new AutodiscoverService
	{ /* Enable tracing.*/
		TraceEnabled = true,
		/* Set the credentials.*/
		Credentials = service.Credentials,
		/* Prevent the AutodiscoverService from */
		/*looking in the local Active Directory */
		/* for the Exchange Web Services Services SCP.*/
		EnableScpLookup = false,
		/* Specify a redirection URL validation */
		/*callback that returns true for valid URLs.*/
		RedirectionUrlValidationCallback =
			RedirectionUrlValidationCallback
	};
	// Get the Exchange Web Services URL for the user's mailbox.
	GetUserSettingsResponse userresponse = ads.GetUserSettings(
		 mUser,
		 UserSettingName.UserDN,
		 UserSettingName.UserDeploymentId,
		 UserSettingName.InternalMailboxServer,
		 UserSettingName.MailboxDN,
		 UserSettingName.PublicFolderServer,
		 UserSettingName.ActiveDirectoryServer,
		 UserSettingName.ExternalMailboxServer,
		 UserSettingName.EcpDeliveryReportUrlFragment,
		 UserSettingName.EcpPublishingUrlFragment,
		 UserSettingName.EcpTextMessagingUrlFragment,
		 UserSettingName.ExternalEwsUrl,
		 UserSettingName.CasVersion,
		 UserSettingName.EwsSupportedSchemas);
	foreach (KeyValuePair<UserSettingName, Object> 
		usersetting in userresponse.Settings)
	{                    
		Console.WriteLine("User Setting Key: " + "usersetting.Key + 
			" - " + "User Setting Value: " + 
				usersetting.Value);
	}
}
catch (AutodiscoverRemoteException ex)
{
	Console.WriteLine("Exception thrown: " + ex.Error.Message);
}
}

public bool RedirectionUrlValidationCallback(String redirectionUrl)
{
	// The default for the validation callback is to reject the URL.
	bool result;

	Uri redirectionUri = new Uri(redirectionUrl);

	// Validate the contents of the redirection URL. 
	//In this simple validation
	// callback, the redirection URL is considered 
	//valid if it is using HTTPS
	// to encrypt the authentication credentials. 
	if (redirectionUri.Scheme == "https")
		result = true;
	else
		result = false;
	return result;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s