How to logon MAPI namespace with profile

J

JC

Hi,

I'm using outlook 2003, I have the following code:

Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")

olNameSpace.Logon MyProfile, "", False, True

When I run it in DLL, I got error "Permission denied", but no dialogue popup.
When I run it in vbscipt, I got dialogue popup to ask user name, password
and domain. I input the correct info. then it logs on fine.
I hope to know how to fix the "Permission denied" issue?
 
M

Michael Bauer

HI,
olNameSpace.Logon MyProfile, "", False, True

for showing a dialog set it´s parameter on true and left the profile
name blank:

olNameSpace.Logon "", "", False, True
 
J

JC

Hi Michael,

I do need to use profile to logon a specified account to access user's
calendar. We have a windows service to call this dll. On service logon we can
setup the logon info. It will pass the logon info into this dll and logon
successfully in outlook 2000, but how to logon in outlook 2003 via program?
 
D

Dmitry Streblechenko \(MVP\)

First of all, you should not be using Outlook in a service. CDO 1.21 was
designed to be used in a service, Outlook was not. Note that if you use CDO
1.21, you will be able to use a dynamic profile - instead of specifying a
profile name, you can pass a server name and the mailbox name separated by
CR/LF.
Secondly, you will most likely need to impersonate that user to avoid the
prompt.
Also note that you can open other user's default folder (assuming that you
have all the required permissions) using Namespace.GetSharedDefaultFolder in
the Outlook Object Model.

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

JC

Hi Dmitry,
Thanks for your help. I know I shouldn't use Outlook in such way, but CDO
dosen't provide the functionalities to update user's calendar, that is why we
have to use outlook object model to update user's calendar via delegate. This
way works fine in outlook 2000, in outlook 2003 look like if we can pass in
the logon info, it will work too( I trired on vbscript). But I don't know how
to pass in?
Thnaks!

JC
 
D

Dmitry Streblechenko \(MVP\)

You cannot use/create dynamic profiles in Outlook Object Model. You need to
use Extended MAPi or CDO 1.21 for that.
Why can't you use Namespace.GetSharedDefaultFolder to access multiple users'
calendars from one profile?

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

JC

We do use Namespace.GetSharedDefaultFolder to access multiple users'
calendar, but we have multi sites - Boston, Hong Kong, Tokyo. Each site has
their own account. Fareast sites has their own Exchange server, so we have
profile for each site. We cannot use one profile to access all user's
calendar. We need to logon with the specified profile. Here are our vbs file

Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")

'olNameSpace.Logon MyProfile, "", False, True
MsgBox olNameSpace.CurrentUser

Set olRecipient = olNameSpace.CreateRecipient(Mailbox)
MsgBox olRecipient.Name

Set olCalendar = olNameSpace.GetSharedDefaultFolder(olRecipient,
9) 'olFolderCalendar
MsgBox "After olNameSpace.GetSharedDefaultFolder"

Set olAppointments = olCalendar.Items

Set olAppointment = olAppointments.Add

Could you tell me how to use Extend MAPI to do the same job? Thanks!
 
D

Dmitry Streblechenko \(MVP\)

Ok, I see what you mean - Exchange provider uses the current process
credentials when connecting to an Exchange server. The only way around this
is to impersonate the user - see LogonUser and ImpersonateLoggedOnUser
functions on MSDN.

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

JC

Hi Dmitry,

I looked LogonUser function, it will return me a token handle, but how to
use it with olNamespace.logon? Could you give me more details? I cannot find
the sample code in MSDN on this. Thanks!
 
D

Dmitry Streblechenko \(MVP\)

You don't use it to make any Outlook calls, when calling LogonUser and then
ImpersonateLoggedOnUser, the process identity switches to the specified
user.
Thinking about it, that won't help you anyway - all Outlook objects are out
of proc, so switching the user identity for the current process won't do
anything, you really need to change the identity of the outlook.exe process.
LogonUser and ImpersonateLoggedOnUser work perfectly for the current process
(I use this technique in quite a few places), but it'll only work inproc
(e.g. if you are using CDO 1.21 or Extended MAPI).
I'd say you are really stretching the Outlook capabilities here; unless you
switch to Extended MAPI or CDO, there is nothing you can do.

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

JC

The issue to use CDO is that CDO dosen't have folder level scurity. If you
logon with CDO, you can access all user's folders, such as inbox. We do not
want that, we hope just access the user's calendar. That is why we use
outlook. On 2003 dose CDO has folder level scurity? If not, is there anything
I can do with CDO to avoid accessing user's inbox?
 
D

Dmitry Streblechenko \(MVP\)

CDO itself does not have any folder level security. Neither does Outlook.
Folder level security is implemented by the Exchange server itself.
If you cannot open a particular folder in Outlook because you do not have
sufficient security rights, you won't be able to do that in CDO either.

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

Dmitry Streblechenko \(MVP\)

No. Redemption is designed to be used with OOM or CDO and it hooks up into
an existing MAPI session.
Why not use CDO 1.21?

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

JC

Hi Dmitry,

I went to the site to read the info. I don't find the sample code to use CDO
to logon with specified profile, such as Coordinator, then from Coordinator
account to access the user's account, if you know where it is, please provide
me the detailed info.

I already show our code, it logon to outlook namespace with specified
profile, such as Coordinator, after logon, if you check the CurrentUser, it
will show "Coordinator".
I tried CDO 1.21 library with the following code:

Dim cdoSession As MAPI.Session
Dim cdoAddrEntry As AddressEntry

Set cdoSession = CreateObject("Mapi.session")
cdoSession.Logon "Coordinator", , False, False, 0 'Use the existing Outlook
session.

After logon, I checked the CurrentUser, I expect to get "Coordinator", but I
got "unknown". Could you show me how to do this with extend MAPI?

Thanks!

JC
 
D

Dmitry Streblechenko \(MVP\)

Are you trying to access other user's Calendar folder? If yes, use
Namespace.GetSharedDefaultFolder.

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

JC

Are you talking about outlook Namespace.GetSharedDefaultFolder? If yes, I
think we are back to the begining. I showed you our code which is using
Namespace.GetSharedDefaultFolder, but before you use Namespace, you need to
logon with spcified profile(I also told you the reason). On outlook 2003 it
will popup a dialogue box to ask user name, password and domain. We are
trying to find workaround. You suggested to use CDO, I tried CDO, it dosen't
return the result as I expect. Could you provide sample code to do the same
thing as the code I provide?
Thanks!
 
K

Ken Slovak - [MVP - Outlook]

You can login to any valid profile or mailbox on the server assuming you
have permissions and know the arguments you need to use. There are samples
of how to do that at www.cdolive.com/cdo5.htm for CDO 1.21. I've used that
to do dynamic logins to every mailbox on an Exchange server running under a
Windows logon that had admin/owner rights to all the mailboxes.
 

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