CDO, Active Directory and Mail Enable
- From: greg.michealson@xxxxxxxxxxx
- Date: 10 Jan 2006 07:43:36 -0800
Can anybody explain why we receive a "type mismatch" error in a mail
enable routine with CDO, ActiveDS and Outlook 2003? The catch is that
it works on
some systems, but not others, so I think it may be a dependency issue.
I've added a comment indicating which line generates the type mismatch
error. The code was pulled from Microsoft's Knowledge Base and the
line that fails has a "< ----- THIS IS THE LINE THAT GENERATES THE TYPE
MISMATCH" by it.
Creating a Distribution List Using CDOEXM and ADSI
--------------------------------------------------------------------------------
Visual Basic
' Creating a Distribution List Using CDOEXM and ADSI
' This sample creates a distribution list in a given Active Directory
container. It uses a slightly
' modified version of the Microsoft Platform SDK code to create a
group, and then
' mail-enables the group using CDOEXM.
' A distribution list in Exchange 2000 is a normal Windows 2000 group,
either security
' or non-security, which has been mail-enabled. This sample uses the
function
' CreateDL to create the distribution list and CDOEXM to mail-enable
it.
Function CreateDL(strPath As String, strGroupName As String,
strSamAcctName As String, strGroupType As String, bSecurity As Boolean)
As IADsGroup
' =========================================================
' CreateDL(strPath As String, strGroupName As String, strSamAcctName As
String,
' strGroupType As String, bSecurity As Boolean)
' strPath = ADsPath of the container under which the group will be
created
' strGroupName = Name of the group to be created
' strSamAcctName = Group name as it will appear to pre-Windows 2000
computers
' strGroupType = Type of group to be created (Local, Domain Local,
Global, or Universal)
' bSecurity = Is this a security group?
' Function returns an IADsGroup object.
' Example of calling the function:
' Set objNewGroup = CreateDL("LDAP://cn=Users,dc=corp,dc=com", "My New
Group", "NewGroup", "Global", False)
' Then add users
' objNewGroup.Add strUser1ADsPath
' objNewGroup.Add strUser2ADsPath
' =========================================================
Dim lGroupType As Long
Dim iAdCont As IADsContainer
Dim iAdGroup As IADsGroup
Dim iMailRecip As IMailRecipient
' --- Set the Type of Group ------
lGroupType = 0
Select Case UCase(strGroupType)
Case "LOCAL": lGroupType = ADS_GROUP_TYPE_LOCAL_GROUP
Case "DOMAIN LOCAL": lGroupType = ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
Case "GLOBAL": lGroupType = ADS_GROUP_TYPE_GLOBAL_GROUP
Case "UNIVERSAL": lGroupType = ADS_GROUP_TYPE_UNIVERSAL_GROUP
Case Else
Debug.Print "This is not a proper group type"
Exit Function
End Select
' ---- Check to See if it is a Security Group ----
If bSecurity Then
lGroupType = lGroupType Or ADS_GROUP_TYPE_SECURITY_ENABLED
End If
' ---- Create the Group ----
Set iAdCont = GetObject(strPath)
Set iAdGroup = iAdCont.Create("group", "cn=" + strGroupName)
iAdGroup.Put "sAMAccountName", strSamAcctName
iAdGroup.Put "groupType", lGroupType
' Flush to the directory
iAdGroup.SetInfo
'--- Mail Enable ----
Set iMailRecip = iAdGroup < ----- THIS IS THE LINE THAT GENERATES THE
TYPE MISMATCH
iMailRecip.MailEnable
' Write Exchange information to the directory.
iAdGroup.SetInfo
' Return the group.
Set CreateDL = iAdGroup
' Clean up.
Set iMailRecip = Nothing
Set iAdGroup = Nothing
Set iAdCont = Nothing
End Function
.
- Follow-Ups:
- Re: CDO, Active Directory and Mail Enable
- From: Glen Scales [MVP]
- Re: CDO, Active Directory and Mail Enable
- Prev by Date: Re: Spoof E-Mail for Demonstration Purposes
- Next by Date: Re: Spoof E-Mail for Demonstration Purposes
- Previous by thread: send mail using vb.net and webdav
- Next by thread: Re: CDO, Active Directory and Mail Enable
- Index(es):
Relevant Pages
|