Create PST

G

Guest

I am using Exchange 2003 as an e-mail server and Outlook 2003 as an e-mail
client. We leave all mail on the server and use Outlook only to view mail.
I would like to write a script, hopefully that a user can run, that will take
a users mailbox and zip it up into a PST file. It is OK (actually best) to
leave the mail on the server but I want it in a PST file for sure. The code
I have right will create a PST file and it will show up when a user opens
Outlook but there is no mail in it and the file is 256K in size. The code is
listed below. Any help would be great.

Function CreateUnicodePST()
Dim myOlApp As New Outlook.Application()
Dim myNameSpace As Outlook.NameSpace
myNameSpace = myOlApp.GetNamespace("MAPI")
myNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
myNameSpace.AddStoreEx("c:\Brian2.pst",
Outlook.OlStoreType.olStoreUnicode)
End Function
 
K

Ken Slovak - [MVP - Outlook]

Your code will have to copy each item in each folder into the PST file from
your mailbox, creating folders in the PST file as you go along after you add
the PST file to the open stores.
 
G

Guest

OK thanks. I'm not sure how I would code to figure out what folders are in
someone's exchange mailbox so I could then copy them to my PST file. Can you
help?
--
Thanks for the help!
Brian


Ken Slovak - said:
Your code will have to copy each item in each folder into the PST file from
your mailbox, creating folders in the PST file as you go along after you add
the PST file to the open stores.
 
D

David C. Holley

Why do you want to have the items in a PST file? What is the ***SPECIFIC
BUSINESS NEED*** to do so? (or) What is the ***SPECIFIC BUSINESS NEED***
to duplicate items on an Exchange Server on a person's PC?

David H
 
K

Ken Slovak - [MVP - Outlook]

Each folder (MAPIFolder) has a Folders collection. So does the NameSpace
object. So you start at NameSpace.Folders(1) to get a top of store folder
(Outlook Today equivalent). When you have the store you want as a MAPIFolder
you get its Folders collection.

Then you recursively iterate each folder in that collection and get each as
a MAPIFolder, then get its Folders collection, etc.

It sounds like a lot of code but if it's written as a recursive procedure it
can be done as a fairly compact procedure.

Once you get a folder you create an equivalent folder in your PST file and
then you get the Items collection of the source folder. You then iterate
that collection and copy each item into the target folder.
 
G

Guest

One reason is that I want to practice doing some Outlook/Exchange
programming. The business reason is that I want a user to be able to create
a .pst file of all of their Exchange e-mail. We are then going to upload
this .pst file to a completely seperate AD/Exchange 2003 domain. We do not
have trusts between the domains and will not have trusts. This script will
help automate some of my testing. If you have some code that would point me
in the right direction that would be great. I've tried to look at the
Outlook object model and a fiew of the other Functions/Classes and I just
can't put the whole program together.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top