1

I´m calling MapiSendMail like this:

lErrorCode := MapiSendMail(0, GetModuleHandle(nil), lMessage, MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);

On my dev server (Win 2016) this returns 0 and opens a new message in outlook (standard mapi client).

However on multiple clients (Win 10 Pro, Win 11 Pro) lErrorCode instead has value 1. According to documentation this means MAPI_E_USER_ABORT:

The user canceled one of the dialog boxes. No message was sent.

Calling SysErrorMessage(GetLastError)) directly after returns

Die angegebene Prozedur wurde nicht gefunden.

Translated:

The specified procedure could not be found.

My guess is that mapi32.dll is not registered correctly or has the wrong version. How would I test this or find another way to solve this problem?

JonasK
  • 149
  • 2
  • 8
  • 2
    From documentation that you linked. _The MAPISendMailW (Unicode) and MAPISendMail (ANSI) functions both send a standard message, with or without any user interaction. The profile must be configured so that either function can open the default service providers without requiring user interaction._ So are you sure that all of your clients have set up mail profile in their Outlook clients? – SilverWarior Jul 12 '23 at 11:37
  • @SilverWarior Yes, I did open a message manually on the clients beforehand – JonasK Jul 12 '23 at 14:07
  • 1
    Being able top open e-Mail message doesn't mean that mail client has properly set-up profile for sending e-Mail messages. For instance on one of my computers I don't have any e-Mail client set-up and yet still if I would double click on any file with *.eml or *.msg extension it would be opened in Outlook client that ships with Windows. Some goes if some application generates e-Mail message. Are you able to send some message from client computer to yourself manually? – SilverWarior Jul 12 '23 at 16:17
  • 1
    Do you have the same problem if you call `MapiLogon()` first, and then pass the session handle to `MapiSendMail()`? – Remy Lebeau Jul 12 '23 at 19:05

1 Answers1

0

Thanks to @RemyLebeau´s comment I found the solution in this stackoverflow post when looking for MapiLogon():

I set the following registry keys as string:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Messaging Subsystem\MAPI="1"
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows Messaging Subsystem\MAPI="1"

Now MapiSendMail() correctly opens a new message in outlook.

JonasK
  • 149
  • 2
  • 8