Exchange Web Services Managed API 1.1 How To
Hallo zusammen
Ich habe mir mal die Exchange Webservices Managed API 1.1 angeschaut
Installation der Web Services Managed API
Programmieren mit VB 2008 Express
Beim Programmieren mit Visual Basic 2008 Express / Visual Basic 2010 Express muss eine Referenz zu der Web Services Managed API DLL hinzugefügt werden. Auf Durchsuchen klicken und die DLL (Microsoft.Exchange.WebServices.dll) auswählen.
In den Projekteigenschaften sieht das dann anschliessend so aus.
Ich habe mir ein kleines Tool gebastelt und einige Eingenschaften über die EWS Managed API abgefragt.
Imports Microsoft.Exchange.WebServices.Data
Imports Microsoft.Exchange.WebServices
'# Connect to EWS Managed API
Dim EWService As New ExchangeService(ExchangeVersion.Exchange2007_SP1)
Dim cred As New System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text, txtDomain.Text)
EWService.Credentials = cred
EWService.AutodiscoverUrl(txtEmailaddress.Text)
'# GET OOF
Dim OOF As New Microsoft.Exchange.WebServices.Data.OofSettings
OOF = EWService.GetUserOofSettings(txtEmailaddress.Text)
Dim IntReply, ExtReply As New Microsoft.Exchange.WebServices.Data.OofReply
Debug.Print("OOF State: " + OOF.State.ToString)
Debug.Print("OOF Duration Start: " + OOF.Duration.StartTime)
Debug.Print("OOF Duration End: " + OOF.Duration.EndTime)
Debug.Print("OOF ExternalAudience: " + OOF.ExternalAudience.ToString) 'All,Known,None
Debug.Print("OOF ExternalReply: " + OOF.InternalReply.Message)
Debug.Print("OOF InternalReply: " + OOF.ExternalReply.Message)
'# SET OOF
Dim OOF As New Microsoft.Exchange.WebServices.Data.OofSettings
Dim IntReply, ExtReply As New Microsoft.Exchange.WebServices.Data.OofReply
Dim StartTime As DateTime = Today
Dim Duration As Microsoft.Exchange.WebServices.Data.TimeWindow
IntReply = "My Internal Reply"
ExtReply = "My External Reply"
Duration = New Microsoft.Exchange.WebServices.Data.TimeWindow(StartTime.AddDays(1), StartTime.AddDays(14))
OOF.State = OofState.Enabled
OOF.ExternalAudience = OofExternalAudience.All
OOF.Duration = Duration
OOF.ExternalReply = ExtReply
OOF.InternalReply = IntReply
EWService.SetUserOofSettings(txtEmailaddress.Text, OOF)
Exchange Management Shell (EMS)
In Exchange kann man die OOF Settings über das folgende CMDlet abgefragt werden.
Get-MailboxAutoReplyConfiguration -Identity Administrator
Powershell mit EWS Managed API
Das ganze kann nun aber auch über Powershell und die EWS Managed API gemacht werden.
###############################
# Powershell GET OOF Settings
###############################
# Import EWS Managed API DLL
Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
# Email Adress
$Email = "Administrator@Public.com"
# Create a new Exchange Service Object
$exchService = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
# Set the Credentials
$exchService.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("Administrator","pa$$word","domain")
# Autodiscover Exchange Webservice URL
$exchService.AutodiscoverUrl($Email)
# Get OOF Settings
$OOF = $exchService.GetUserOofSettings($Email)
###############################
# Powershell SET OOF Settings
###############################
# Import EWS Managed API DLL
Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
# Email Adress
$Email = "Administrator@Public.com"
# Create a new Exchange Service Object
$exchService = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
# Set the Credentials
$exchService.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("Administrator","pa$$word","domain")
# Autodiscover Exchange Webservice URL
$exchService.AutodiscoverUrl($Email)
# Create a new OofSettings object
$OSettings = new-object Microsoft.Exchange.WebServices.Data.OofSettings
$IoofReply =new-object Microsoft.Exchange.WebServices.Data.OofReply("I am OOF Internal")
$EoofReply =new-object Microsoft.Exchange.WebServices.Data.OofReply("I am OOF External")
# Define OOF Settings
$startTime = [DateTime]::Today
$timeWindow = new-object Microsoft.Exchange.WebServices.Data.TimeWindow($startTime.AddDays(1), $startTime.AddDays(10))
$OSettings.Duration =$timeWindow
$OSettings.InternalReply = $IoofReply
$OSettings.ExternalReply = $EoofReply
$OSettings.Duration = $timeWindow
# All,Known,None
$OSettings.ExternalAudience =[Microsoft.Exchange.WebServices.Data.OofExternalAudience]::All
# Disabled,Enabled,Scheduled
$OSettings.State =[Microsoft.Exchange.WebServices.Data.OofState]::Enabled
# Set OOF Settings
$exchService.SetUserOofSettings($Email,$OSettings)
Grüsse
Andres Bohren