Search code examples
delphioutlookmapidelphi-10.4-sydneymapisendmail

Delphi MapiSendMail returns MAPI_E_USER_ABORT


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?


Solution

  • 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.