This example shows how to provision a Microsoft Exchange 2000 or Exchange 2003 mail-enabled user in Forefront Identity Manager Synchronization Service (FIM Synchronization Service). The example assumes that you are using the Active Directory Connector (ADC) to maintain interoperability between Exchange 5.5 and Active Directory Domain Services (AD DS).

Note:
Microsoft Exchange 5.5 is deprecated.

Attribute Inclusion List

You must select the following attributes from the Select Attributes property page for your AD DS management agent to provision an Exchange mail-enabled user:

Creating a Mail-Enabled User in a Homogeneous Exchange Environment

The following example shows how to use a rules extension to provision an Exchange mail-enabled user. You must add a reference to logging.dll to use the LogException method.

Visual Basic  Copy Code
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

	Dim isExch2003 As Boolean

	isExch2003 = false  ' Exchange 2000 server

	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.CreateMailEnabledUser(adMA, dn, nickName, targetAddress, isExch2003)
		End If

		' Log and rethrow any exception.
		Catch ex As Exception
			Logging.Logging.LogException(ex, "Provision", "Caught exception", False)
			Throw
	End Try
End Sub
C#  Copy Code
void IMVSynchronization.Provision (MVEntry mventry)
{
	ConnectedMA adMA;
	CSEntry csentry;
	String nickName, targetAddress;
	ReferenceValue dn;
	Boolean isExch2003;

	isExch2003 = false;  // Exchange 2000 server

	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.CreateMailEnabledUser(adMA, dn, nickName, targetAddress, isExch2003);
	}
}

	// Log and rethrow any exception.
	catch(Exception ex)
	{
		Logging.Logging.LogException(ex, "Provision", "Caught exception", false);
		throw;
}
}

Creating a Mail-Enabled User 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 call the CreateMailEnabledUser 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 user in a mixed Exchange environment. You must add a reference to logging.dll to use the LogException method.

Visual Basic  Copy Code
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
   
   ' Exchange 2000 server
	Dim isExch2003 As Boolean = false 

	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.CreateMailEnabledUser(adMA, dn, nickName, targetAddress, isExch2003)

			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
C#  Copy Code
void IMVSynchronization.Provision (MVEntry mventry)
{
	ConnectedMA adMA;
	CSEntry csentry;
	String nickName, targetAddress, rdnWithoutType, rdn, adminGroup;
	ReferenceValue dn;
	int equalSignInRDN;

	// Exchange 2000 server
	Boolean isExch2003 = false;  

	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.CreateMailEnabledUser(adMA, dn, nickName, targetAddress, isExch2003);

			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

Reference

CreateMailEnabledUser

Concepts

Microsoft Exchange Connected Data Sources

[an error occurred while processing this directive]