Mail-Enabling a User
You can easily mail-enable a user with very little code using ADSI and CDOEXM. The following code shows you how to mail-enable a single user specified by a known DN:
' This code mail enables a user.
Option Explicit
Dim strUserDN, strEmailAddr, objUser
' ------ SCRIPT CONFIGURATION ------
strUserDN = "<UserDN>" ' e.g. cn=DrAmy,cn=Users,dc=mycorp,dc=com
strEmailAddr = "<EmailAddress>" 'e.g. Agramzow@AcmeConsulting.com
' ------ END CONFIGURATION ---------
Set objUser = GetObject("LDAP://" & strUserDN)
objUser.MailEnable
strEmailAddr
objUser.Put "internetEncoding",1310720
objUser.SetInfo( )
WScript.Echo "Successfully mail-enabled user."Tip
Mail-enabling a user requires Exchange Data Administrator permissions.
This should all be familiar, with the exception of MailEnable. MailEnable is a method of the IMailRecipient CDOEXM interface. For a user, it takes a single argument: the email address to associate with the user. In the background, the specific changes made by the MailEnable method are on the user object in Active Directory and include changes to the following attributes:
targetAddressmailNicknamemAPIRecipientlegacyExchangeDN
Warning
You are probably looking at that list of attributes and thinking, "Hey, I can just populate those attributes with LDAP calls; I don't even need to use CDOEXM!" To be honest, that is almost true. It is only "almost" true for two reasons: first, depending on which knowledge base articles you read, you will find confusion ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access