Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Programmatically Create and Mail enable a contact in Exchange 2003

Posted on 2006-06-23
2
Medium Priority
?
545 Views
Last Modified: 2007-12-19
I am having problems mail enabling a contact in Exchange 2003 after I create it using VB6. I have referenced the following:

cdoex.dll
cdoexm.dll
activeds.tlb

Here is the code I am using (I have changed the actual domain names and stuff):
There is a single command button control on the form called cmdGo.

Option Explicit
Dim oIADs As IADs
Dim oContainer As IADsContainer
Dim strSMTP, strFN, strLN, strDN, strCont, strDom As String
Dim strUserName, strTargetMailAddress, strDomain As String
Dim blResult As Boolean

Private Sub cmdGo_Click()

On Error Resume Next
Err.Clear

strSMTP = "tester@test.net"
strFN = "Test"
strLN = "Contact"
strDN = "Test Contact"
strCont = "CN=Contacts"
strDom = "DC=testlab,DC=test,dc=com"

Set oIADs = GetObject("LDAP://rootDSE")
Set oContainer = GetObject("LDAP://" & strCont & "," & strDom)
Set oIADs = oContainer.Create("contact", "cn=" + CStr(strDN))

oIADs.Put "mail", CStr(strSMTP)
oIADs.Put "targetAddress", CStr(strSMTP)
oIADs.Put "givenName", CStr(strFN)
oIADs.Put "sn", CStr(strLN)
oIADs.Put "displayName", CStr(strDN)
oIADs.SetInfo


If Err.Number = 0 Then
    Call MailEnableCDOPerson(CStr(strDN), CStr(strSMTP), CStr(strCont), CStr(strDom))
    MsgBox "Success!"
Else
    MsgBox "Failure!"
End If

strSMTP = ""
strFN = ""
strLN = ""
strDN = ""
Set oIADs = Nothing
Set oContainer = Nothing

End Sub

Sub MailEnableCDOPerson(strUserName As String, _
                             strTargetMailAddress As String, _
                             strContainer As String, _
                             strDomain As String)

    Dim oPerson             As New CDO.Person
    Dim oRecipient          As CDOEXM.IMailRecipient

    'Target address should look like this
    'strTargetMailAddress = strLastName & "@microsoft.com"

    ' get the user
    oPerson.DataSource.Open "LDAP://CN=" & strUserName & "," & strContainer & "," & strDomain

    ' MailEnable
    Set oRecipient = oPerson
    oRecipient.MailEnable strTargetMailAddress

    oPerson.DataSource.Save

    MsgBox strUserName + " mail enabled successfully"

    'CleanUp
    Set oPerson = Nothing
    Set oRecipient = Nothing

End Sub

The code creates the contact but does not mail enable it. I have poured through technet, MSDN and google, and everything they have given me does not work. Help.
0
Comment
Question by:GusGallows
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Author Comment

by:GusGallows
ID: 17012003
Never mind. I found the problem. By default, the "oPerson.DataSource.Open" is opened in read only. You have to add the following to the line:
, , adModeReadWrite

So it should look as follows:

oPerson.DataSource.Open "LDAP://CN=" & strUserName & "," & strContainer & "," & strDomain, , adModeReadWrite


I did that and I was able to create Mail Enabled Contacts in active directory from my XP workstation. Also get rid of the following two lines:
oIADs.Put "mail", CStr(strSMTP)
oIADs.Put "targetAddress", CStr(strSMTP)

It gives an error that an email address already exists if you use them before doing the mailenable. Add the "mail" one back after the mail enable. You do not need the "targetAddress" one at all.
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 17014232
Closed, 500 points refunded.
kb
Experts Exchange Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question