MAPILogon failes when not used in GUI-Thread

D

DanielH

Hi,

I am using MAPI in a C#-Program via a wrapper-class which simple DLLImports
the functions from mapi32.dll.
I am calling MAPILogon like this:
MAPILogon(hwnd, null, null, 0, 0, ref session);
hwnd is IntPtr.Zero (NULL in C++).
When I call this code somewhere in FormShow or similar (in the GUI-Thread)
anything works fine, I get logged in without being prompted anything.
Now, I have a Socket which asynchroniously listens on a port. When some data
is being received I am in a new thread. In this thread the same code from
above failes with the error-code 3 (MAPI_E_LOGIN_FAILURE?)
Why? Please help, this is kinda urgent...

Thanks a lot in advance
 
D

Dan Mitchell

=?Utf-8?B?RGFuaWVsSA==?= said:
I am using MAPI in a C#-Program via a wrapper-class which simple
DLLImports the functions from mapi32.dll.

You do know that this is officially unsupported, right?

http://support.microsoft.com/kb/813349

I am calling MAPILogon like this:
MAPILogon(hwnd, null, null, 0, 0, ref session);
hwnd is IntPtr.Zero (NULL in C++).
When I call this code somewhere in FormShow or similar (in the
GUI-Thread) anything works fine, I get logged in without being
prompted anything. Now, I have a Socket which asynchroniously listens
on a port. When some data is being received I am in a new thread. In
this thread the same code from above failes with the error-code 3
(MAPI_E_LOGIN_FAILURE?) Why? Please help, this is kinda urgent...

I'd guess that the code isn't running as a user that has permission to
log into the profile that your code is trying to use. Are you trying to
pass the session between threads? When your code is running in the main
thread, it's not logging in as such, it's just hooking onto the existing
Outlook session -- in the other thread, it has to create a session to
log into, so it may well be trying to pop up a dialog behind the scenes
and failing. Try passing in the name of the profile you're using, that
might help.

-- dan

-- dan
 
D

DanielH

Dan Mitchell said:
You do know that this is officially unsupported, right?

http://support.microsoft.com/kb/813349

No, I didn't know, that it is not supported... How can I then send an eMail
via Outlook in .NET?
I'd guess that the code isn't running as a user that has permission to
log into the profile that your code is trying to use. Are you trying to
pass the session between threads? When your code is running in the main
thread, it's not logging in as such, it's just hooking onto the existing
Outlook session -- in the other thread, it has to create a session to
log into, so it may well be trying to pop up a dialog behind the scenes
and failing. Try passing in the name of the profile you're using, that
might help.

I tried to pass the profile-name - no changes.
The user the program is running the program is local admin, so this
shouldn't be a problem...
I don't see the difference between the main-thread and any other thread. Why
is one thread simply hooking into the existing session and one thread not?

Thanks for your answer
 
K

Ken Slovak - [MVP - Outlook]

Jumping in here for Dan. Neither Extended MAPI nor CDO 1.21 is supported for
..NET code, it might work sometimes but you can't rely on it. You must use
the Outlook object model or a wrapper for Extended MAPI that works across
the Interop such as Redemption (www.dimastr.com/redemption).
 
D

Dan Mitchell

Ken Slovak - said:
Jumping in here for Dan. Neither Extended MAPI nor CDO 1.21 is
supported for .NET code, it might work sometimes but you can't rely on
it.

To be precise, quoting from a MS support guy in another newsgroup:

"It's the sort of thing that'll mostly work. It'll work while you're
writing it. Then it'll work while you're testing it. It'll work while your
customer is evaluating it. Then as soon as the customer deploys it - BAM!
That's when it'll decide to start having problems. And Microsoft ain't
gonna help you with it, since we told you not to do it in the first place.
:)"
You must use the Outlook object model or a wrapper for Extended
MAPI that works across the Interop such as Redemption
(www.dimastr.com/redemption).

There's also mapi33.net, which a lot of people seem to have had success
with, though it's still not supported by MS.

-- dan
 

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