Skip to content

Performing Exchange tasks

To create an Exchange mailbox for a user, you need to use the IAdmExchangeMailboxOps interface, which is implemented by all ADSI objects representing users. In order to get this interface, you need to bind to the user object in Active Directory.

To create a mailbox, call the CreateMailbox method of the interface. The first parameter of the method specifies the mailbox alias. The alias can be a combination of characters separated by a period with no intervening spaces. You can use value references in the mailbox alias, for example, %username%. Value references will be replaced with corresponding property values of the user account.

The second parameter of the method specifies the ADS path of the database where the new mailbox will be created. The ADS path should be formatted as Adaxes://<DatabaseDN>, where <DatabaseDN> is the distinguished name (DN) of the mailbox database. For details on how to get the DN of a mailbox database, see Get the DN of a mailbox database.

The following code sample creates an Exchange mailbox for a user.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$alias = "%username%"
$mailboxDatabaseDN =
    "CN=DB 1,CN=Databases,CN=Exchange Administrative Group," +
    "CN=Administrative Groups,CN=First Organization,CN=Microsoft Exchange," +
    "CN=Services,CN=Configuration,DC=domain,DC=com"

# Bind to user object
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Create a mailbox
$user.CreateMailbox($alias, "Adaxes://$mailboxDatabaseDN")
using System;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        const String userDN = "CN=John Smith,CN=Users,DC=domain,DC=com";
        const String alias = "%username%";
        const String mailboxDatabaseDN =
            "CN=DB 1,CN=Databases,CN=Exchange Administrative Group," +
            "CN=Administrative Groups,CN=First Organization,CN=Microsoft Exchange," +
            "CN=Services,CN=Configuration,DC=domain,DC=com";

        // Bind to user object
        IADs user = (IADs)admService.OpenObject("Adaxes://" + userDN, null, null, 0);

        // Create a mailbox
        IAdmExchangeMailboxOps mailboxOps = (IAdmExchangeMailboxOps)user;
        mailboxOps.CreateMailbox(alias, "Adaxes://" + mailboxDatabaseDN);
    }
}

Moving mailboxes

To move Exchange mailboxes between databases, use the CreateMoveMailboxRequest method of the IAdmMoveExchangeMailboxOps interface, which is implemented by all ADSI objects representing AD user accounts.

Tip

The CreateMoveMailboxRequest method moves mailboxes asynchronously, meaning that the method call will return before the mailbox move is completed.

The method allows you to move the primary mailbox and/or the archive mailbox of a user. If you want to move the primary mailbox, specify the ADS path of the target mailbox database as the first parameter of the method. If you don’t want to move the primary mailbox, pass NULL to the parameter. The ADS path should be formatted as Adaxes://<DatabaseDN>, where <DatabaseDN> is the distinguished name (DN) of the target mailbox database. For details on how to get the DN of a mailbox database, see Get the DN of a mailbox database.

The following code sample moves the primary mailbox of a user to the mailbox database called DB 2.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$targetDatabaseDN =
    "CN=DB 2,CN=Databases,CN=Exchange Administrative Group," +
    "CN=Administrative Groups,CN=First Organization,CN=Microsoft Exchange," +
    "CN=Services,CN=Configuration,DC=domain,DC=com"

# Bind to user object
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Move the mailbox
$user.CreateMoveMailboxRequest("Adaxes://$targetDatabaseDN", $NULL, 0, 0)
using System;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        const String userDN = "CN=John Smith,CN=Users,DC=domain,DC=com";
        const String targetDatabaseDN =
            "CN=DB 2,CN=Databases,CN=Exchange Administrative Group," +
            "CN=Administrative Groups,CN=First Organization,CN=Microsoft Exchange," +
            "CN=Services,CN=Configuration,DC=domain,DC=com";

        // Bind to user object
        IADs user = (IADs)admService.OpenObject("Adaxes://" + userDN, null, null, 0);

        // Move the mailbox
        IAdmMoveExchangeMailboxOps moveOps = (IAdmMoveExchangeMailboxOps)user;
        moveOps.CreateMoveMailboxRequest("Adaxes://" + targetDatabaseDN, null, 0, 0);
    }
}

Tip

Moving mailboxes to/from Microsoft 365

You can use the IAdmMoveExchangeMailboxOps2 interface to move mailboxes between on-premises Exchange and Microsoft 365. However, it is available on the server side only and can be used in scripts executed via Business Rules, Custom Commands, and Scheduled Tasks.

Exporting mailboxes

To export the primary mailbox of a user to a Personal Storage Table (PST) file, you need to call the CreateMailboxExportRequest method of the IAdmExportExchangeMailboxOps interface supported by all user objects. The first parameter of the method specifies the full UNC path to the exported PST file. The method will return an export request ID that can be used to check the status of the request. To check the status, use the GetMailboxExportRequestInfo method of the same interface.

Tip

The CreateMailboxExportRequest method exports mailboxes asynchronously, meaning that the method call will return before the mailbox export is completed.

The following code sample exports a user’s mailbox to PST.

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

$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$filePath = "\\SERVER\Backups\JSmith.pst"

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

# Bind to the user
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Export the mailbox
$requestId = $user.CreateMailboxExportRequest($filePath, 0, 0)

# Get mailbox export request info
$requestInfo = $user.GetMailboxExportRequestInfo($requestId, $False)

while($requestInfo.Status -eq "ADM_EXPORTMAILBOXSTATUS_INPROCESS")
{
    Start-Sleep -Seconds 30
    $requestInfo = $user.GetMailboxExportRequestInfo($requestId, $False)
}

# Status
Write-Host "Status: " -NoNewline
switch ($requestInfo.Status)
{
    "ADM_EXPORTMAILBOXSTATUS_SUCCEEDED"
    {
        Write-Host "The mailbox has been exported successfully"
    }
    "ADM_EXPORTMAILBOXSTATUS_FAILED"
    {
        Write-Host $requestInfo.FailureMessage
    }
}
using System;
using System.Threading;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;

class Program
{
    static void Main(string[] args)
    {
        const String userDN = "CN=John Smith,CN=Users,DC=domain,DC=com";
        const String filePath = @"\\SERVER\Backups\JSmith.pst";

        // Connect to Adaxes service
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to the user
        IAdmExportExchangeMailboxOps user = (IAdmExportExchangeMailboxOps)admService.OpenObject(
            "Adaxes://" + userDN, null, null, 0);

        // Export the mailbox
        String requestId = user.CreateMailboxExportRequest(filePath, 0, 0);

        // Get mailbox export request info
        IAdmExportExchangeMailboxRequestInfo requestInfo =
            user.GetMailboxExportRequestInfo(requestId, false);

        while (requestInfo.Status == ADM_EXPORTMAILBOXSTATUS_ENUM.ADM_EXPORTMAILBOXSTATUS_INPROCESS)
        {
            Thread.Sleep(30000);
            requestInfo = user.GetMailboxExportRequestInfo(requestId, false);
        }

        Console.Write("Status: ");
        switch (requestInfo.Status)
        {
            case ADM_EXPORTMAILBOXSTATUS_ENUM.ADM_EXPORTMAILBOXSTATUS_SUCCEEDED:
                Console.WriteLine("The mailbox has been exported successfully.");
                break;
            case ADM_EXPORTMAILBOXSTATUS_ENUM.ADM_EXPORTMAILBOXSTATUS_FAILED:
                Console.WriteLine(requestInfo.FailureMessage);
                break;
        }
    }
}

Mail-enabling contacts and groups

In order to establish an e-mail address in Exchange for a group, contact, or user, you need to call the MailEnable method of the IAdmExchangeMailOps interface, which is supported by all ADSI objects representing groups, contacts, and users. For details on how to bind to Active Directory objects, see Binding to ADSI objects.

The first parameter of the MailEnable method specifies the e-mail alias. You can use value references in the alias, for example, %sAMAccountName%, or %firstname%%lastname%. Value referenecs will be replaced with corresponding property values of the Active Directory object on which the method is called.

When mail-enabling a user or contact, you need to pass the external email address as the second parameter, and the type of the email address as the third parameter of the method. When mail-enabling a group, both parameters must be NULL.

The following code sample mail-enables a group in Exchange.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to group object
$groupDN = "CN=My Group,CN=Users,DC=domain,DC=com"
$group = $admService.OpenObject("Adaxes://$groupDN", $NULL, $NULL, 0)

# Mail-enable the group
$alias = "%sAMAccountName%"
$group.MailEnable($alias, $NULL, $NULL, $NULL)
using System;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to group object
        const String groupDN = "CN=My Group,CN=Users,DC=domain,DC=com";
        IADs group = (IADs)admService.OpenObject("Adaxes://" + groupDN, null, null, 0);

        // Mail-enable the group
        const String alias = "%samAccountName%";
        IAdmExchangeMailOps mailOps = (IAdmExchangeMailOps)group;
        mailOps.MailEnable(alias, null, null, null);
    }
}

Accessing Exchange properties

To get properties of a mailbox, mail-enabled contact or distribution list, first you need to bind to the object in Active Directory. All user, group, and contact objects support the IAdmExchangeMailParametersOps interface, using which you can access object’s Exchange properties by calling the GetMailParameters method of the interface.

Tip

Calling the GetMailParameters method is expensive with regard to performance, as it fetches all Exchange-related information of an object.

The following code sample gets the alias of a mailbox.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to user object
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Read Exchange properties
$exchangeProps = $user.GetMailParameters()

# Get the alias
$alias = $exchangeProps.Alias
Write-Host "Alias:" $alias
using System;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to user object
        IADs user = (IADs)admService.OpenObject(
            "Adaxes://CN=John Smith,CN=Users,DC=company,DC=com", null, null, 0);

        // Read Exchange properties
        IAdmExchangeMailParametersOps exchangeOps = (IAdmExchangeMailParametersOps)user;
        IAdmExchangeMailParameters exchangeProps = exchangeOps.GetMailParameters();

        // Get the alias
        String alias = exchangeProps.Alias;
        Console.WriteLine("Alias: " + alias);
    }
}

The GetMailParameters method returns the IAdmExchangeMailParameters interface, which is common for mailboxes, mail-enabled contacts, and distribution lists. The table below shows additional interfaces that are supported by various Exchange recipient types.

Recipient Type Interface
Mailbox IAdmExchangeMailboxParameters
Mail-enabled contact IAdmExchangeMailContactParameters
Mail-enabled group IAdmExchangeMailGroupParameters

It means that if you need to access Exchange properties that are specific to mailboxes, you need to use the IAdmExchangeMailboxParameters interface. To access properties specific to mail-enabled contacts and distribution lists, use IAdmExchangeMailContactParameters and IAdmExchangeMailGroupParameters interfaces correspondingly.

The following code sample uses the IAdmExchangeMailboxParameters interface to get the name of the database a mailbox belongs to.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to user object
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Get the mailbox database name
$mailboxProps = $user.GetMailParameters()
$mailboxDB = $mailboxProps.StorageDatabase
Write-Host "Mailbox database:" $mailboxDB
using System;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to user object
        IADs user = (IADs)admService.OpenObject(
            "Adaxes://CN=John Smith,CN=Users,DC=company,DC=com", null, null, 0);

        // Get the mailbox database name
        IAdmExchangeMailParametersOps exchangeOps = (IAdmExchangeMailParametersOps)user;
        IAdmExchangeMailboxParameters mailboxProps =
            (IAdmExchangeMailboxParameters)exchangeOps.GetMailParameters();
        String mailboxDB = mailboxProps.StorageDatabase;
        Console.WriteLine("Mailbox database: " + mailboxDB);
    }
}

For information on how to access specific Exchange properties, see Accessing specific Exchange properties.

For more samples, see

Modifying Exchange properties

To modify Exchange properties of an object, first you need to bind to the Active Directory object that represents the mailbox, contact, or distribution list that you want to modify. All user, group, and contact objects support the IAdmExchangeMailParametersOps interface. To update Exchange properties of the object, call the SetMailParameters method of the interface.

The first parameter of the SetMailParameters method represents the modifications to be made to the object. The type of the parameter is IAdmExchangeMailParameters. So, before calling the SetMailParameters method, you need to create an instance of the IAdmExchangeMailParameters interface. Depending on whether you want to modify parameters of a mailbox, mail-enabled contact, or mail-enabled group, you need to use different classes to instantiate the interface. Apart from the IAdmExchangeMailParameters interface, which is common for all recipient types, each class supports additional interfaces that are specific to each recipient type.

The table below specifies which class must be used to update different recipient types, and which interfaces are supported by each class.

Recipient Type Class Interfaces
Mailbox AdmExchangeMailboxParameters IAdmExchangeMailParameters, IAdmExchangeMailboxParameters
Mail-enabled contact AdmExchangeMailContactParameters IAdmExchangeMailParameters, IAdmExchangeMailContactParameters
Mail-enabled group AdmExchangeMailGroupParameters IAdmExchangeMailParameters, IAdmExchangeMailGroupParameters

The following code sample enables ActiveSync for a mailbox user.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to user object
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

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

# Enable the ActiveSync mailbox feature
$activeSyncFeature = $mailboxParams.MailboxFeatures.Create(
    "ADM_EXCHANGE_MAILBOXFEATURETYPE_ACTIVESYNC")
$activeSyncFeature.Enabled = $True
$mailboxParams.MailboxFeatures.Add($activeSyncFeature)

# Save the changes
$user.SetMailParameters($mailboxParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to user object
        IADs user = (IADs)admService.OpenObject(
            "Adaxes://CN=John Smith,CN=Users,DC=company,DC=com", null, null, 0);

        // Create an instance of the AdmExchangeMailboxParameters class
        AdmExchangeMailboxParameters mailboxParams =
            new AdmExchangeMailboxParameters();

        // Enable the ActiveSync mailbox feature
        IAdmExchangeMailboxFeature activeSyncFeature = mailboxParams.MailboxFeatures.Create(
            ADM_EXCHANGE_MAILBOXFEATURETYPE_ENUM.ADM_EXCHANGE_MAILBOXFEATURETYPE_ACTIVESYNC);
        activeSyncFeature.Enabled = true;
        mailboxParams.MailboxFeatures.Add(activeSyncFeature);

        // Save the changes
        IAdmExchangeMailParametersOps mailOps = (IAdmExchangeMailParametersOps)user;
        mailOps.SetMailParameters(mailboxParams,
            ADM_SET_EXCHANGE_PARAMS_FLAGS_ENUM.ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE);
   }
}

The following code sample hides a distribution list from Exchange address lists.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to group object
$groupDN = "CN=My Group,CN=Users,DC=domain,DC=com"
$group = $admService.OpenObject("Adaxes://$groupDN", $NULL, $NULL, 0)

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

# Hide from address lists
$groupParams.HiddenFromExchangeAddressList = $True

# Save the changes
$group.SetMailParameters($groupParams, "ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE")
using Softerra.Adaxes.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to group object
        IADs group = (IADs)admService.OpenObject(
            "Adaxes://CN=My Group,CN=Users,DC=company,DC=com", null, null, 0);

        // Create an instance of the AdmExchangeMailGroupParameters class
        AdmExchangeMailGroupParameters mailboxParams =
            new AdmExchangeMailGroupParameters();

        // Hide from address lists
        mailboxParams.HiddenFromExchangeAddressList = true;

        // Save the changes
        IAdmExchangeMailParametersOps mailOps = (IAdmExchangeMailParametersOps)group;
        mailOps.SetMailParameters(mailboxParams,
            ADM_SET_EXCHANGE_PARAMS_FLAGS_ENUM.ADM_SET_EXCHANGE_PARAMS_FLAGS_NONE);
   }
}

The second parameter of the SetMailParameters method indicates whether to resolve value references when applying changes. The type of the parameter is ADM_SET_EXCHANGE_PARAMS_FLAGS_ENUM. If you want to update Exchange properties using modification templates that contain value references, you need to set the parameter to ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES.

The following code sample adds an SMTP email address to multiple mail-enabled contacts. The email address will be their Employee ID plus ‘@example.com’. The script will use the following email address template %employeeID%@example.com. Value reference %employeeID% contained in the template will be replaced with the value of the Employee ID property of each contact object.

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# DNs of the contact objects to update
$contactDNs = @(
    "CN=Contact 1,CN=Users,DC=company,DC=com",
    "CN=Contact 2,CN=Users,DC=company,DC=com",
    "CN=Contact 3,CN=Users,DC=company,DC=com")

# Create an instance of the AdmExchangeMailContactParameters class
$contactParams =
    New-Object "Softerra.Adaxes.Adsi.Exchange.AdmExchangeMailContactParameters"
# Add a new modification
$emailAddresses = $contactParams.EmailAddresses
$emailAddresses.OverrideOldValues = $False
$newAddress = $emailAddresses.CreateAddress("ADM_EXCHANGE_ADDRTYPE_SMTP", $null)
$newAddress.Address = "%employeeID%@example.com"
$emailAddresses.Add("ADS_PROPERTY_APPEND", $newAddress)
$contactParams.EmailAddresses = $emailAddresses

# Apply changes
foreach ($contactDN in $contactDNs)
{
    $contact = $admService.OpenObject("Adaxes://$contactDN", $NULL, $NULL, 0)

    $contact.SetMailParameters($contactParams,
        "ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES")
}
using System;
using Softerra.Adaxes.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.Cache;
using Softerra.Adaxes.Interop.Adsi.Exchange;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // DNs of the contact objects to update
        String[] contactDNs = new String[] {
            "CN=Contact 1,CN=Users,DC=company,DC=com",
            "CN=Contact 2,CN=Users,DC=company,DC=com",
            "CN=Contact 3,CN=Users,DC=company,DC=com" };

        // Create an instance of the AdmExchangeMailContactParameters class
        AdmExchangeMailContactParameters contactParams =
            new AdmExchangeMailContactParameters();
        // Add a new modification
        IAdmExchangeProxyAddressModificationCollection emailAddresses =
            contactParams.EmailAddresses;
        emailAddresses.OverrideOldValues = false;
        IAdmExchangeProxyAddress newAddress =
            emailAddresses.CreateAddress(
                ADM_EXCHANGE_ADDRTYPE_ENUM.ADM_EXCHANGE_ADDRTYPE_SMTP, null);
        newAddress.Address = "%employeeID%@example.com";
        emailAddresses.Add(ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_APPEND,
            newAddress);
        contactParams.EmailAddresses = emailAddresses;

        // Apply changes
        foreach (String contactDN in contactDNs)
        {
            IADs contact =
                (IADs)admService.OpenObject("Adaxes://" + contactDN, null, null, 0);

            IAdmExchangeMailParametersOps contactOps =
                (IAdmExchangeMailParametersOps)contact;
            contactOps.SetMailParameters(contactParams,
                ADM_SET_EXCHANGE_PARAMS_FLAGS_ENUM.
                    ADM_SET_EXCHANGE_PARAMS_FLAGS_RESOLVEVALUEREFERENCES);
        }
    }
}

For more samples, see

Accessing specific Exchange properties

The following tables show how to access specific Exchange properties using interfaces provided by Adaxes ADSI API.

General

Property
Type
API
Alias String IAdmExchangeMailParameters::Alias
Display name String IAdmExchangeMailParameters::SimpleDisplayName
Hide from address lists Boolean IAdmExchangeMailParameters::HiddenFromExchangeAddressList
Custom attributes IAdmExchangeCustomAttributes IAdmExchangeMailParameters::CustomAttributes
Mailbox database String IAdmExchangeMailboxParameters::StorageDatabase
Archive database String IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_ARCHIVE”).DatabaseName
User MAPI rich text format ADM_EXCHANGE_USEMAPIRICHTEXTFORMATTYPE_ENUM IAdmExchangeMailContactParameters::UseMapiRichTextFormat
Expansion server IAdmObjectReference IAdmExchangeMailGroupParameters::ExpansionServer
Send out-of-office message to originator Boolean IAdmExchangeMailGroupParameters::SendOofMessageToOriginator
Send delivery reports to group manager Boolean IAdmExchangeMailGroupParameters::ReportToManager
Send delivery reports to message originator Boolean IAdmExchangeMailGroupParameters::ReportToOriginator

Mailbox usage

Property Type API
Mailbox size IAdmByteQuantifiedSize IAdmExchangeMailboxParameters::UsageInfo.Size
Total items Int32 IAdmExchangeMailboxParameters::UsageInfo.TotalItemCount
Last logon date DateTime IAdmExchangeMailboxParameters::UsageInfo.LastLogonDate
Logged on by String IAdmExchangeMailboxParameters::UsageInfo.LastLogonUserName
Storage quotas IAdmExchangeStorageQuotas IAdmExchangeMailboxParameters::StorageQuotas

E-mail address

Property
Type
API
E-mail addresses IAdmExchangeProxyAddressModificationCollection IAdmExchangeMailParameters::EmailAddresses
Automatically update e-mail addresses based on e-mail policy Boolean IAdmExchangeMailParameters::EmailAddressPolicyEnabled

Mailbox policies

Property Type API
Sharing policy IAdmObjectReference IAdmExchangeMailboxParameters::IAdmObjectReference
Role Assignment policy IAdmObjectReference IAdmExchangeMailboxParameters::RoleAssignmentPolicy
Retention policy IAdmObjectReference IAdmExchangeMailboxParameters::RetentionPolicy
Address Book policy IAdmObjectReference IAdmExchangeMailboxParameters::AddressBookPolicy
Managed Folder policy IAdmObjectReference IAdmExchangeMailboxParameters::ManagedFolderMailboxPolicy

Mailbox features

Property
Type
API
Outlook Web App IAdmExchangeMailboxFeature,
IAdmExchangeMailboxOwaFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_OWA”)
ActiveSync IAdmExchangeMailboxFeature,
IAdmExchangeMailboxActiveSyncFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_ACTIVESYNC”)
Unified Messaging IAdmExchangeMailboxFeature,
IAdmExchangeMailboxUnifiedMessagingFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_UNIFIEDMESSAGING”)
MAPI IAdmExchangeMailboxFeature IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_MAPI”)
POP3 IAdmExchangeMailboxFeature,
IAdmExchangeMailboxProtocolFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_POP3”)
IMAP IAdmExchangeMailboxFeature,
IAdmExchangeMailboxProtocolFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_IMAP”)
Archiving IAdmExchangeMailboxFeature,
IAdmExchangeMailboxArchiveFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_ARCHIVE”)
Retention Hold IAdmExchangeMailboxFeature,
IAdmExchangeMailboxRetentionHoldFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_RETENTIONHOLD”)
Litigation Hold IAdmExchangeMailboxFeature,
IAdmExchangeMailboxLitigationHoldFeature
IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_LITIGATIONHOLD”)
Outlook Mobile Access (2003 only) IAdmExchangeMailboxFeature IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_OMA”)
User Initiated Synchronization (2003 only) IAdmExchangeMailboxFeature IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_UIS”)
Up-to-date Notifications (2003 only) IAdmExchangeMailboxFeature IAdmExchangeMailboxParameters::MailboxFeatures.GetItemByType
(“ADM_EXCHANGE_MAILBOXFEATURETYPE_UDN”)

Mail flow

Property Type API
Delivery Options IAdmExchangeDeliveryOptions IAdmExchangeMailParameters::MailFlowSettings.DeliveryOptions
Message Size Restrictions IAdmExchangeMessageSizeRestrictions IAdmExchangeMailParameters::MailFlowSettings.MessageSizeRestrictions
Message Delivery Restrictions IAdmExchangeMessageDeliveryRestrictions IAdmExchangeMailParameters::MailFlowSettings.MessageDeliveryRestrictions
Delivery Management (Groups) IAdmExchangeMessageDeliveryRestrictions IAdmExchangeMailParameters::MailFlowSettings.MessageDeliveryRestrictions
Message Approval (Groups) IAdmExchangeMessageModeration IAdmExchangeMailParameters::MailFlowSettings.MessageModeration

Delegation

Property
Type
API
Send As IAdmObjectReferenceModificationCollection IAdmExchangeMailParameters::SendAs
Send on Behalf Of IAdmObjectReferenceModificationCollection IAdmExchangeMailParameters::GrantSendOnBehalfTo
Full Access IAdmObjectReference[] IAdmExchangeMailboxParameters::MailboxRights.GetTrusteesGrantedRights
(“ADM_EXCHANGE_MAILBOX_RIGHTS_FULL_ACCESS”)
Mailbox Rights IAdmExchangeMailboxRights IAdmExchangeMailboxParameters::MailboxRights

Miscellaneous

Property Type API
MailTip String IAdmExchangeMailParameters::MailTip
Automatic Replies (OOF) IAdmExchangeMailboxAutoReplyConfiguration IAdmExchangeMailboxParameters::AutoReplyConfiguration
Calendar Settings IAdmExchangeMailboxCalendarSettings IAdmExchangeMailboxParameters::CalendarSettings

See also