Exchange 2000 Development
How to create a mail-enabled public folder using CDO
Two things are needed to be known before this code can be executed. The first is the URL of the folder to be created and, secondly, the mail address of the folder.
Two object declarations are required to make the code work:
Dim oMailRecipient As cdoexm.IMailRecipient
Dim oMailingListFolder As CDO.Folder
This is the main body of the code:
sEMail = "Public.Folder@dragondrop.com"
Set oMailingListFolder = New CDO.Folder
With oMailingListFolder
sDescription = oFrmCreateMailingList.txtMailingListName
.Description = sDescription
.ContentClass = "urn:contact-classes:mailfolder"
' Save to the public store
.DataSource.SaveTo sNewFolderPath [1]
End With
' Set the mail attributes
'
Set oMailRecipient = oMailingListFolder [2]
With oMailRecipient
.HideFromAddressBook = False
.SMTPEmail = sEMail [3]
oMailingListFolder.DataSource.Save [4]
' Add the main mail address to the Proxy addresses
AddAddressToProxyAddresses oMailingListFolder, "SMTP:" & sEMail [5]
End With
oMailingListFolder.DataSource.Save [6]
Notes:
[1] Create the folder and save it to the required URL path.
[2] Create an instance of an cdoexm.IMailRecipient pointer and point it to the newly created public folder. In actual fact this points to the mail interface of the folder.
[3] Set the .SMTP property to associate the folder with the e-mail address. There is, equally, an .X400 property.
[4] Save the folder again to make sure that the changes are saved.
[5] Add any proxy addresses to the folder.
[6] Save the folder again to make the latest set of changes persistant.
Depending on the speed of the replication of the Exchange Servers in your network the updates will be visible shortly in Outlook on the client machines or in the Exchange System Manager on the other servers.
This AddAddressToProxyAddresses() routine adds a e-mail address to the Proxy Address list. The address is only added to the list if it isn't already present.
Please note that for SMTP mail, for example, the proxy addresses have to be prefixed with 'SMTP:' or 'smtp:'. The former is for the primary mail address of the folder and the latter lower case is for the proxy addresses.
Private Sub AddAddressToProxyAddresses(oMailRecipient As cdoexm.IMailRecipient, sAddress As String)
Dim vProxyAddresses As Variant
Dim nProxyAddresses As Long
Dim nProxyAddress As Long
Dim bIsFound As Boolean
bIsFound = False
vProxyAddresses = oMailRecipient.ProxyAddresses
nProxyAddresses = UBound(vProxyAddresses)
nProxyAddress = 0
Do While nProxyAddress <= nProxyAddresses
If vProxyAddresses(nProxyAddress) = sAddress Then
bIsFound = True
Exit Do
End If
nProxyAddress = nProxyAddress + 1
Loop
If Not bIsFound Then
ReDim Preserve vProxyAddresses(nProxyAddresses + 1)
vProxyAddresses(nProxyAddresses + 1) = sAddress
oMailRecipient.ProxyAddresses = vProxyAddresses
End If
End Sub
|