Share via


Example: Mail-enabled Contact

This example shows how to provision an Exchange 2000 or Exchange 2003 mail-enabled contact. The example assumes that you are using the Active Directory Connector (ADC) to maintain interoperability between Exchange 5.5 and Active Directory.

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 mail-enabled contact:

  • mailNickname
  • targetAddress
  • legacyExchangeDN (If you are supporting a mixed Exchange environment. See Creating a Mail-enabled Contact in a Mixed Exchange Environment, below.)

Creating a Mail-enabled Contact in a Homogeneous Exchange Environment

The following example shows how to use a rules extension to provision an Exchange mail-enabled contact. 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, targetAddress As String
        Dim dn as ReferenceValue
    
        try
            adMA          = mventry.ConnectedMAs("Fabrikam AD MA")
    
            nickName      = mventry("mailNickname").Value
            targetAddress = mventry("targetAddress").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.CreateMailEnabledContact(adMA, dn, nickName, targetAddress)
            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, targetAddress;
        ReferenceValue dn;
    
        try
        {
            adMA          = mventry.ConnectedMAs["Fabrikam AD MA"];
    
            nickName      = mventry["mailNickname"].Value;
            targetAddress = mventry["targetAddress"].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.CreateMailEnabledContact(adMA, dn, nickName, targetAddress);
            }
        }
    
        // Log and rethrow any exception
        catch(Exception ex)
        {
            Logging.Logging.LogException(ex, "Provision", "Caught exception", false);
            throw;
        }
    }

Creating a Mail-enabled Contact in a Mixed Exchange Environment

If your environment includes a mixed configuration of Exchange 5.5 and Exchange 2000 or Exchange 2003 servers and you are using the Active Directory connector to synchronize with Exchange 5.5, you must perform an additional step after you have called the CreateMailEnabledContact() method in your provisioning process: You must update the legacyExchangeDN connector to an Administrative Group to which a connection agreement of the Active Directory connector points.

The following example shows how to use a rules extension to provision an Exchange mail-enabled contact in a mixed Exchange environment. 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, targetAddress, rdnWithoutType, rdn, adminGroup As String
        Dim dn as ReferenceValue
        Dim equalSignInRDN As Integer
    
        try
            adMA          = mventry.ConnectedMAs("Fabrikam AD MA")
    
            nickName      = mventry("mailNickname").Value
            targetAddress = mventry("targetAddress").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.CreateMailEnabledContact(adMA, dn, nickName, targetAddress)
    
                equalSignInRDN = csentry.RDN.ToString().IndexOf("=")
                rdnWithoutType = csentry.RDN.Substring(equalSignInRDN + 1)
                rdn            = "cn=" + rdnWithoutType + "-" + System.Guid.NewGuid().ToString()
                adminGroup     = "CN=First Administrative Group,CN=Administrative Groups,CN=Fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com"
    
                csentry("legacyExchangeDN").Value = adminGroup + "/" + rdn
            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, targetAddress, rdnWithoutType, rdn, adminGroup;
        ReferenceValue dn;
        int equalSignInRDN;
    
        try
        {
            adMA          = mventry.ConnectedMAs["Fabrikam AD MA"];
    
            nickName      = mventry["mailNickname"].Value;
            targetAddress = mventry["targetAddress"].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.CreateMailEnabledContact(adMA, dn, nickName, targetAddress);
    
                equalSignInRDN = csentry.RDN.ToString().IndexOf("=");
                rdnWithoutType = csentry.RDN.Substring(equalSignInRDN + 1);
                rdn            = "cn=" + rdnWithoutType + "-" + System.Guid.NewGuid().ToString();
                adminGroup     = "CN=First Administrative Group,CN=Administrative Groups,CN=Fabrikam,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=fabrikam,DC=com";
    
                csentry["legacyExchangeDN"].Value = adminGroup + "/" + rdn;
            }
        }
    
        // Log and rethrow any exception
        catch(Exception ex)
        {
            Logging.Logging.LogException(ex, "Provision", "Caught exception", false);
            throw;
        }
    }

See Also

CreateMailEnabledContact(ConnectedMA,ReferenceValue,String,String)

Send comments about this topic to Microsoft

Build date: 2/16/2009