Skip to content

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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the contact
$contactDN = "CN=My Contact,CN=Users,DC=domain,DC=com"
$contact = $admService.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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the contact
$contactDN = "CN=My Contact,CN=Users,DC=domain,DC=com"
$contact = $admService.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