"I'm sending e-mails using Simple MAPI from a Delphi 7 program. This has worked perfectly for years. The last two weeks or so, two of our customers are getting the error "external exception 241938E". I have tried to find this code on the internet, but there is no mention of it. Does anybody know this error? Both customers are running on Terminal Server, using Outlook as an mail client on an Office 365 server"
The above message was posted by another poster but was closed I feel prematurely. I have the EXACT circumstances. Two completely unrelated customers with unrelated software packages (one developed in D7 about a decade ago, one developed in XE3 about 3 years ago). Only think they have in common is they both utilise MAPI for the sending of emails and they are both operating under a Terminal Server environment. Both clients have independent installation of our program. ie. they have a copy of the application running directly off their own desktop. So it is not a shared instance of the program that might be used by multiple users at the one time. I don't know enough about Microsoft Office and its installation. I assume that use of that is shared.
I have embedded EurekaLog but it was all to no avail. Through my own internal logging, I have been able to ascertain the exact point at which the error is rendered. It is in the call to load the MAPI DLL library. The exact line of code is below where MAPIModule is a HModule and MAPIDLL is the value straight out of the MAPI APi - i.e. 'MAPI32.DLL'.
MAPIModule := LoadLibrary(PChar(MAPIDLL));
The one thing I am adamant is that it is not constant. From my own tests, I was able to send 2 emails out of 13 attempts spaced out over an hour of testing. No rime or reason as to why it worked those two occasions. But 11 of the attempts failed at that exact same spot.
[ MORE DETAILS ]
The code below is executed to trigger the SendMail.
MapiModule is the handle returned by the LoadLibrary call. The value returned is passed through to GetProcAddress. The GetProcAddress fails, and the EXTERNAL EXCEPTION error is raised.
Unfortunately, I do not have intimate knowledge of EurekaLog but to the best of my knowledge I have enabled all valid options. But no error log file is ever created.
Despite the error handling routine capturing the error and returning a value of 99 (something I use to designate an undefined error), the front-end application becomes unusable. It is not frozen, not crashed. Timers are functioning and screen refreshes continue. But it becomes locked and unable to accept user entry - as if control was passed to Outlook to handle the sending of the email but not returned.
Declaration of SM is now included. It points to a function declared in the MAPI API.
TFNMapiSendMail = function(lhSession: LHANDLE; ulUIParam: ULONG_PTR;
var lpMessage: TMapiMessage; flFlags: FLAGS;
ulReserved: ULONG): ULONG stdcall;
var SM : TFNMapiSendMail;
MAPIModule := LoadLibrary(PChar(MAPIDLL));
if MAPIModule = 0 then
begin
Result := 'MAPI Library not found';
end
else
begin
try
@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SM <> nil then
begin
try
MAPIError := SM(0, Application.Handle, MapiMessage, MAPI_DIALOG or
MAPI_LOGON_UI, 0);
except
MAPIError := 99;
end;
end
else
begin
MAPIError := 1;
end;
finally
FreeLibrary(MAPIModule);
end;
end;