RE: Scripting Public Folders

  • From: "Michael B. Smith" <michael@xxxxxxxxxx>
  • To: "[ExchangeList]" <exchangelist@xxxxxxxxxxxxx>
  • Date: Fri, 13 May 2005 10:17:21 -0400

Here ya go. This also fixes a couple of bugs in the microsoft example.
' Function:
' createPublicFolder
' Purpose:
' Creates a mapi public folder with the specified name (from the
' root of the mapi folder tree).
' Input:
' strFolderName  Name of public folder
' Output:   
' createPublicFolder Contains Error code (if any)
' Based on:
Function createPublicFolder (ByVal strFolderName)
 Dim objFolder
 Dim strConnString
 Dim strDefaultDomain
 Dim strStorageName
 On Error Resume Next
 Call GetDefaultSMTPDomain (strDefaultDomain)
 ' Get the WSS name.
 strStorageName = "file://./backofficestorage/" & strDefaultDomain & "/"
 ' Build the folder name.
 strConnString = strStorageName & "public folders/" & strFolderName
 ' Create the folder.
 Set objFolder = CreateObject ("cdo.folder")
 If Err.Number Then
  createPublicFolder = Err.Number
  e "Couldn't createobject for " & strConnString
  Exit Function
 End If
 ' Set the folder properties.
 With objFolder
  .Description = "Root folder for " & strFolderName
  .ContentClass = "urn:content-classes:folder"
("";) =
  .DataSource.SaveTo strConnString
 End With
 If Err.Number Then
  createPublicFolder = Err.Number
  e "Couldn't SaveTo/Create " & strConnString
  Exit Function
 End If
 createPublicFolder = 0
 ' Clean up.
 Set objFolder = Nothing
 e "Created " & strConnString
End Function
' Function:
' GetDefaultSMTPDomain
' Purpose:
' Obtains the default SMTP domain for the organization, which defines
' the WSS/BackOfficeStorage filename.
' Output:   
' strDefault   Contains the default SMTP domain
' Based on:
' My own code
Sub GetDefaultSMTPDomain (ByRef strDefault)
 Dim strAddress   ' string
 Dim strAddresses ' collection of addresses
 Dim objPolicy    ' reference to Default Recipient Policy
 strDefault = ""
 Set objPolicy = GetObject ("LDAP://CN=Default Policy,CN=Recipient
Policies," + strOrgDN)
 strAddresses  = objPolicy.Get ("gatewayProxy")
 ' strAddresses contains all the addresses specified on the 
 ' E-Mail Addresses tab of the default recipient policy
 For Each strAddress in strAddresses
  If Left (strAddress, 5) = "SMTP:" Then
   strDefault = Right (strAddress, Len (strAddress) - 6) ' strip SMTP:@
  End If
  dp "Email address suffix: " & strAddress
 ' Report our results
 e "Default SMTP address for organization: " & strDefault
 Set strAddresses = Nothing
 Set objPolicy = Nothing
End Sub


From: Tim Sutton [mailto:T.Sutton@xxxxxxxxxx] 
Sent: Friday, May 13, 2005 10:09 AM
To: [ExchangeList]
Subject: [exchangelist] Scripting Public Folders

Hi all! 

Is it possible / does anyone know of a script that can be used to create
public folders? Basically we're using public folders to store incoming
and outgoing job related e-mails and sometimes the list comes through
for a lot of folders to be created in one go. I'd ideally like to script
this to save a lot of time and effort, but I don't even know if it's

Thanks for any help :) 

For Troup Bywaters + Anders     

Tim Sutton              

T: +44 (0) 113 243 2241 
F: +44 (0) 113 242 4024                 
E: t.sutton@xxxxxxxxxx <mailto:t.sutton@xxxxxxxxxx>           
W: <>

Eastgate House 
10 Eastgate                                     
LS2 7JL 
Office Location Map


Groupshield 6.0 - Troup Bywaters & Anders
Privilege and Confidentiality Notice
This email and any attachments to it are intended only for the party to
whom they are addressed. They may contain privileged and / or
confidential information. If you have received this transmission in
error please notify the sender immediately and delete any digital copies
and destroy any paper copies. Thank you.

List Archives:
Exchange Newsletters:
Exchange FAQ:
Other Internet Software Marketing Sites:
World of Windows Networking:
Leading Network Software Directory:
No.1 ISA Server Resource Site:
Windows Security Resource Site:
Network Security Library:
Windows 2000/NT Fax Solutions:
You are currently subscribed to this Discussion List as:
To unsubscribe visit
Report abuse to listadmin@xxxxxxxxxxxxxx 

Other related posts: