Exchange Mailboxes and Redemptions SafeCurrentUser

D

dedejavu

Hi Outlook experts,
I am trying to get the current user's exchange folder.
I know that a user can view other user's folders so I want to avoid
those. I can find the folder I want using
objNameSpace.folders.Item("MailBox - " & objNameSpace.CurrentUser)
but I get the security prompt from CurrentUser.
SafeCurrentUser gives me a different name variation than CurrentUser so
I can't use it to find the folder. CurrentUser ='LastName FirstName
(EmailID)' SafeCurrentUser.name ='FirstName LastName'
I can't just loop through the folders to look for a folder starting
with "MailBox" because there might be several.
Any suggestions would be so appreciated.
Thanks
Pachydermitis
 
K

Ken Slovak - [MVP - Outlook]

NameSpace.GetDefaultFolder(olFolderInbox).Parent should get you what you
want.
 
D

dedejavu

Thanks for the tip Ken,
Unfortunately my use of GetDefaultFolder often returns a folder from
within the user's [Personal Folders] (based on how the user has it set
up). Are there other ways to setup the namespace differently or
something to ensure I return an exchange folder? Or perhaps is there
some other property in my namespace or one of propties redemption makes
accessible the I could use instead?
Thanks
Pachydermitis
 
K

Ken Slovak - [MVP - Outlook]

Most of the useful properties like that would be in a folder level above
TopOfStore so you'd need to use CDO 1.21 or Extended MAPI to get at the
InfoStore level. However, there are a few things you can do anyway.

You could use NameSpace.Folders, which returns the set of top level folders.
Iterate that collection and look for "Mailbox" in the MAPIFolder.Name
property of each top level folder.

You could also use a hack where the store provider is part of the StoreID of
a folder. If it's an Exchange store the StoreID string would contain
"EMSDB.DLL" and if it's a PST provider it would contain "mspst.dll". Use a
case insensitive comparison for that.
 
D

Dmitry Streblechenko

Look at the Namespace.GetSharedDefaultFolder. Note that you can open current
user's mailbox as well as somebody's else mailbox.
Also note that the Exchange provider does not like being a secondary store
(it looks like a PST store is the default one even though you are using
Exchange, right?).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
D

dedejavu

Thanks for looking at this Dmitry,
You are right, PST is the default store and I am using Exchange as
well.
I'm not exactly sure what you are saying about
GetSharedDefaultFold­er. Are you saying that I can use
Namespace.GetSharedDefaultFold­er to get a users exchange folder even
if a pst is the default store? I messed around with it but was not
able to.

I can use objNameSpace.folders.Item("Mai­lBox - " &
objNameSpace.CurrentUser) to get the exchange folder,
but I get the security prompt from CurrentUser. SafeCurrentUser gives
me a different name variation than CurrentUser.
Thanks again
Pachydermitis
 
D

dedejavu

Ken,
Thanks for your help. I have learned a lot from the examples you post
in answer to other peoples questions.
You method is essentially the method I am using now, except that I have
to contend with the possibilty of several exchange folders.
A user may have access to another exchange user's folder. Currently I
look at each of the 'Mailbox - " folders and then see if the user's
name is in the folder name (in any form). It's an ugly hack, and I'm
sure there is a better way.
Thanks
Pachydermitis
 
K

Ken Slovak - [MVP - Outlook]

Well, if a PST file is the default store and the Exchange mailbox is a
secondary store that's an ugly situation and really not at all a good
practice for many reasons. Unfortunately in that case you can't use the
method of getting the default Inbox and its parent folder.

In your case I'd probably get the current user name and examine the mailbox
string from the top of store folders just as you are. Ugly situations
sometimes demand ugly code :)
 
D

Dmitry Streblechenko

Try to call Namespace.CreateRecipient, then use the returned object to call
Namespace.GetSharedDefaultFold­er.
Again, making the Exchange mailbox the default store might be your only
option...

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Thanks for looking at this Dmitry,
You are right, PST is the default store and I am using Exchange as
well.
I'm not exactly sure what you are saying about
GetSharedDefaultFold­er. Are you saying that I can use
Namespace.GetSharedDefaultFold­er to get a users exchange folder even
if a pst is the default store? I messed around with it but was not
able to.

I can use objNameSpace.folders.Item("Mai­lBox - " &
objNameSpace.CurrentUser) to get the exchange folder,
but I get the security prompt from CurrentUser. SafeCurrentUser gives
me a different name variation than CurrentUser.
Thanks again
Pachydermitis
 

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