Share via


Example: Mailbox

This example shows how to provision an Exchange 2000 or Exchange 2003 mailbox object.

Attribute Inclusion List

You must select the following attributes from the Select Attributes property page for your Active Directory management agent to provision an Exchange mailbox:

  • mailNickname
  • homeMDB
  • msExchMailboxSecurityDescriptor

The following example shows how to provision an Exchange mailbox. Be sure to add a reference to logging.dll to use the LogException method.

    Public Sub Provision(ByVal mventry As MVEntry) _
        Implements IMVSynchronization.Provision
    
        Dim adMA As ConnectedMA
        Dim csentry As CSEntry
        Dim nickName, mailboxMDB As String
        Dim dn as ReferenceValue
    
        try
            adMA = mventry.ConnectedMAs("Fabrikam AD MA")
    
            nickName   = mventry("mailNickname").Value
            mailboxMDB = mventry("homeMDB").Value
    
            ' Construct the distinguished name
            dn = adMA.EscapeDNComponent("CN=" + mventry("cn").Value).Concat("ou=mailboxes,dc=fabrikam,dc=com")
    
            If 0 = adMA.Connectors.Count then
                csentry = ExchangeUtils.CreateMailbox(adMA, dn, nickName, mailboxMDB)
            End If
    
            ' Log and rethrow any exception
            Catch ex As Exception
                Logging.Logging.LogException(ex, "Provision", "Caught exception", False)
                Throw
        End Try
    End Sub
    void IMVSynchronization.Provision (MVEntry mventry)
    {
        ConnectedMA adMA;
        CSEntry csentry;
        String nickName, mailboxMDB;
        ReferenceValue dn;
    
        try
        {
            adMA = mventry.ConnectedMAs["Fabrikam AD MA"];
    
            nickName   = mventry["mailNickname"].Value;
            mailboxMDB = mventry["homeMDB"].Value;
    
            // Construct the distinguished name
            dn = adMA.EscapeDNComponent("CN=" + mventry["cn"].Value).Concat("ou=mailboxes,dc=fabrikam,dc=com");
    
            if(0 == adMA.Connectors.Count)
            {
                csentry = ExchangeUtils.CreateMailbox(adMA, dn, nickName, mailboxMDB);
            }
        }
    
        // Log and rethrow any exception
        catch(Exception ex)
        {
            Logging.Logging.LogException(ex, "Provision", "Caught exception", false);
            throw;
        }
    }

See Also

CreateMailbox(ConnectedMA,ReferenceValue,String,String)

Send comments about this topic to Microsoft

Build date: 2/16/2009