E-mail addresses

The following code sample modifies e-mail addresses of a mail-enabled contact.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the contact
$contactDN = "CN=My Contact,CN=Contacts,DC=domain,DC=com"
$contact = $service.OpenObject("Adaxes://$contactDN", $null, $null, 0)

# Create an instance of the AdmExchangeMailContactParameters class
$contactParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailContactParameters"

# Don't update e-mail addresses based on e-mail address policy automatically 
$contactParams.EmailAddressPolicyEnabled = $false

$emailAddresses = $contactParams.EmailAddresses

# Create a new SMTP address
$emailAddress = $emailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_SMTP", $null)
$emailAddress.Address = "%firstname%%lastname%@example.local"
$emailAddress.IsPrimary = $true

# Add the new address to the existing list
$emailAddresses.Add("ADS_PROPERTY_APPEND", $emailAddress)
$emailAddresses.OverrideOldValues = $false
$contactParams.EmailAddresses = $emailAddresses

# Save changes
$contact.SetMailParameters($contactParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")

The following code sample sets the external email address of the contact.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the contact
$contactDN = "CN=My Contact,CN=Contacts,DC=domain,DC=com"
$contact = $service.OpenObject("Adaxes://$contactDN", $null, $null, 0)

# Create an instance of the AdmExchangeMailContactParameters class
$contactParams = New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailContactParameters"

$emailAddresses = $contactParams.EmailAddresses

# Create a new SMTP address
$emailAddress = $emailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_SMTP", $null)
$emailAddress.Address = "%firstname%.%lastname%@example.com"

# Set as the new address as the extrnal address of the Contact
$contactParams.ExternalEmailAddress = $emailAddress

# Save changes
$contact.SetMailParameters($contactParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")

See also