1

Topic: MapiSendMailW in Windows 10

Good afternoon!
Prompt, kind people, I suffer the third day.
After update on 1803 in wind10 (well, all programs using WinAPI ceased to work for us at least).
These are two programs from scanners and .
By these machines costs The Bat, but after problem appearance tried both Outlook, and Thunderbird (three different machines, everywhere win10 and , before update worked).
Procedure of creation of the outgoing letter has been found on open spaces still about 10 years ago and worked all this time, and now continues to work on 7. And here on 10 - a fig.
MAPISendMail returns the code 2 MAPI_E_FAILURE One or more unspecified errors occurred. No message was sent.
Rewrote the unit under usage MAPISendMailW
[spoiler]

unit SendMailUnit;
interface
uses Classes, Sysutils, Forms, Winapi. Windows, Winapi. MAPI;
function SendEmail (const RecipName, RecipAddress, RecipCopyAddress;
Subject, BodyText: String; Attachment: TStringList): Boolean;
type
PWSTR = PWideChar;
PMapiFileDescW = ^TMapiFileDescW;
MapiFileDescW = record
ulReserved: ULONG; {Reserved for future use (must be 0)}
flFlags: ULONG; {Flags}
nPosition: ULONG; {character in text to be replaced by attachment}
lpszPathName: PWSTR; {Full path name of attachment file}
lpszFileName: PWSTR; {Original file name (optional)}
lpFileType: LPVOID; {Attachment file type (can be lpMapiFileTagExt)}
end;
TMapiFileDescW = MapiFileDescW;
PMapiRecipDescW = ^TMapiRecipDescW;
MapiRecipDescW = record
ulReserved: ULONG; {Reserved for future use}
ulRecipClass: ULONG; {Recipient class}
{MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG}
lpszName: PWSTR; {Recipient name}
lpszAddress: PWSTR; {Recipient address (optional)}
ulEIDSize: ULONG; {Count in bytes of size of pEntryID}
lpEntryID: LPVOID; {System-specific recipient reference}
end;
TMapiRecipDescW = MapiRecipDescW;
PMapiMessageW = ^TMapiMessageW;
MapiMessageW = record
ulReserved: ULONG; {Reserved for future use (M.B. 0)}
lpszSubject: PWSTR; {Message Subject}
lpszNoteText: PWSTR; {Message Text}
lpszMessageType: PWSTR; {Message Class}
lpszDateReceived: PWSTR; {in YYYY/MM/DD HH:MM format}
lpszConversationID: PWSTR; {conversation thread ID}
flFlags: FLAGS; {unread, return receipt}
lpOriginator: PMapiRecipDescW; {Originator descriptor}
nRecipCount: ULONG; {Number of recipients}
lpRecips: PMapiRecipDescW; {Recipient descriptors}
nFileCount: ULONG; {# of file attachments}
lpFiles: PMapiFileDescW; {Attachment descriptors}
end;
TMapiMessageW = MapiMessageW;
TFNMapiSendMailW = function (lhSession: LHANDLE; ulUIParam: ULONG_PTR;
var lpMessage: TMapiMessageW; flFlags: FLAGS;
ulReserved: ULONG): ULONG stdcall;
implementation
var
sendMailW: TFNMapiSendMailW;
MAPIModule: HModule = 0;
MAPIDLL: string = ' MAPI32.DLL ';
function MapiSendMailW (lhSession: LHANDLE; ulUIParam: ULONG_PTR;
var lpMessage: TMapiMessageW; flFlags: FLAGS; ulReserved: ULONG): ULONG;
begin
MAPIModule: = LoadLibrary (PChar (MAPIDLL));
@SendMailW: = GetProcAddress (MAPIModule, ' MAPISendMailW ');
if @SendMailW <> nil then
Result: = SendMailW (lhSession, ulUIParam, lpMessage, flFlags, ulReserved)
else Result: = 2;
end;
function SendEmailAnsi (const RecipName, RecipAddress, RecipCopyAddress;
Subject, BodyText: String; Attachment: TStringList): Boolean;
var
MapiMessage: TMapiMessage;
MapiFileDesc: array of TMapiFileDesc;
MapiRecipDesc: array of TMapiRecipDesc;
i: integer;
begin
if RecipCopyAddress <> "then
begin
SetLength (MapiRecipDesc, 2);
with MapiRecipDesc [0] do
begin
ulReserved: = 0;
ulRecipClass: = MAPI_TO;
lpszName: = PAnsiChar (AnsiString (RecipName));
lpszAddress: = PAnsiChar (AnsiString (RecipAddress));
ulEIDSize: = 0;
lpEntryID: = nil;
end;
with MapiRecipDesc [1] do
begin
ulReserved: = 0;
ulRecipClass: = MAPI_CC;
lpszName: = PAnsiChar (AnsiString (RecipName));
lpszAddress: = PAnsiChar (AnsiString (RecipCopyAddress));
ulEIDSize: = 0;
lpEntryID: = nil;
end;
end else
begin
SetLength (MapiRecipDesc, 1);
with MapiRecipDesc [0] do
begin
ulReserved: = 0;
ulRecipClass: = MAPI_TO;
lpszName: = PAnsiChar (AnsiString (RecipName));
lpszAddress: = PAnsiChar (AnsiString (RecipAddress));
ulEIDSize: = 0;
lpEntryID: = nil;
end;
end;
SetLength (MapiFileDesc, Attachment. Count);
for i: = 0 to Attachment. Count - 1 do
with MapiFileDesc [i] do
begin
ulReserved: = 0;
flFlags: = 0;
nPosition: = i;
lpszPathName: = PAnsiChar (AnsiString (Attachment. Strings [i]));
lpszFileName: = nil;
lpFileType: = nil;
end;
with MapiMessage do
begin
ulReserved: = 0;
lpszSubject: = PAnsiChar (AnsiString (Subject));
lpszNoteText: = PAnsiChar (AnsiString (BodyText));
lpszMessageType: = nil;
lpszDateReceived: = nil;
lpszConversationID: = nil;
flFlags: = 0;
lpOriginator: = nil;
if RecipCopyAddress <> "then
nRecipCount: = 2 else
nRecipCount: = 1;
lpRecips: = @MapiRecipDesc [0];
if Attachment. Count> 0 then
begin
nFileCount: = Attachment. Count;
lpFiles: = @MapiFileDesc [0];
end
else
begin
nFileCount: = 0;
lpFiles: = nil;
end;
end;
i: = MapiSendMail (0, Application. Handle, MapiMessage, MAPI_DIALOG
or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
Result: = i = SUCCESS_SUCCESS;
end;
function SendEmailW (const RecipName, RecipAddress, RecipCopyAddress;
Subject, BodyText: String; Attachment: TStringList): Boolean;
var
MapiMessageW: TMapiMessageW;
MapiFileDescW: array of TMapiFileDescW;
MapiRecipDescW: array of TMapiRecipDescW;
i: integer;
begin
if RecipCopyAddress <> "then
begin
SetLength (MapiRecipDescW, 2);
with MapiRecipDescW [0] do
begin
ulReserved: = 0;
ulRecipClass: = MAPI_TO;
lpszName: = PChar (RecipName);
lpszAddress: = PChar (RecipAddress);
ulEIDSize: = 0;
lpEntryID: = nil;
end;
with MapiRecipDescW [1] do
begin
ulReserved: = 0;
ulRecipClass: = MAPI_CC;
lpszName: = PChar (RecipName);
lpszAddress: = PChar (RecipCopyAddress);
ulEIDSize: = 0;
lpEntryID: = nil;
end;
end else
begin
SetLength (MapiRecipDescW, 1);
with MapiRecipDescW [0] do
begin
ulReserved: = 0;
ulRecipClass: = MAPI_TO;
lpszName: = PChar (RecipName);
lpszAddress: = PChar (RecipAddress);
ulEIDSize: = 0;
lpEntryID: = nil;
end;
end;
SetLength (MapiFileDescW, Attachment. Count);
for i: = 0 to Attachment. Count - 1 do
with MapiFileDescW [i] do
begin
ulReserved: = 0;
flFlags: = 0;
nPosition: = i;
lpszPathName: = PChar (Attachment. Strings [i]);
lpszFileName: = nil;
lpFileType: = nil;
end;
with MapiMessageW do
begin
ulReserved: = 0;
lpszSubject: = PChar (Subject);
lpszNoteText: = PChar (BodyText);
lpszMessageType: = nil;
lpszDateReceived: = nil;
lpszConversationID: = nil;
flFlags: = 0;
lpOriginator: = nil;
if RecipCopyAddress <> "then
nRecipCount: = 2 else
nRecipCount: = 1;
lpRecips: = @MapiRecipDescW [0];
if Attachment. Count> 0 then
begin
nFileCount: = Attachment. Count;
lpFiles: = @MapiFileDescW [0];
end
else
begin
nFileCount: = 0;
lpFiles: = nil;
end;
end;
i: = MapiSendMailW (0, Application. Handle, MapiMessageW, MAPI_DIALOG
or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
MessageBox (Application. Handle, Pchar (IntToStr (i)), ", 0);
Result: = i = SUCCESS_SUCCESS;
end;
function SendEmail (const RecipName, RecipAddress, RecipCopyAddress;
Subject, BodyText: String; Attachment: TStringList): Boolean;
begin
Result: = SendEmailW (RecipName, RecipAddress, RecipCopyAddress, Subject, BodyText, Attachment);
end;
end.

[/spoiler]
MapiSendMailW returns the same 2 MAPI_E_FAILURE
Pancake, what is necessary to it, and, prompt? sad
PS changed programs by default, here so the register at present looks:

[HKEY_LOCAL_MACHINE \SOFTWARE \CLIENTS \MAIL]
@="The Bat!"
[HKEY_LOCAL_MACHINE \SOFTWARE \CLIENTS \MAIL \THE Bat!]
"DLLPath" = "C: \\Program Files \\The Bat! \\TBMapi64.dll"
@="The Bat!"

Thanks!

2

Re: MapiSendMailW in Windows 10

Using WinAPI Simple MAPI smile

3

Re: MapiSendMailW in Windows 10

The program 32-x the bit?

4

Re: MapiSendMailW in Windows 10

Aniskin, yes. Tried 32 Bath, 32 Thunderbird - the same result

5

Re: MapiSendMailW in Windows 10

In notification messages of debugger DLL boots?

6

Re: MapiSendMailW in Windows 10

GunSmoker;

if @SendMailW <> nil then
Result: = SendMailW (lhSession, ulUIParam, lpMessage, flFlags, ulReserved)//here performance comes

or somehow still it is necessary to look?

7

Re: MapiSendMailW in Windows 10

View / Debug Windows / Event log.
Well or Process Monitor th.

8

Re: MapiSendMailW in Windows 10

It is necessary to look, whether it is loaded TBMapi32.dll

9

Re: MapiSendMailW in Windows 10

Also look at a HKEY_CURRENT_USER \Software \Clients \mail branch, instead of a HKEY_LOCAL_MACHINE \SOFTWARE \Clients \mail.

10

Re: MapiSendMailW in Windows 10

And still recalled. I do not know, what version at you The Bat, but old versions had misimplementation MAPISendMailW, the error is corrected since version 7.4.16.

11

Re: MapiSendMailW in Windows 10

I thank for variants!
Dll unit is loaded:

Process regindoc.exe (9012)
Source Breakpoint at $00FF3743: C:\Project\DMITRY \! XE2\RegInDoc\SendMailUnit.pas line 65. Process regindoc.exe (9012)
Module Load: MAPI32.dll. No Debug Info. Base Address: $642A0000. Process regindoc.exe (9012)
Thread Start: Thread ID: 3028. Process regindoc.exe (9012)
Thread Start: Thread ID: 12776. Process regindoc.exe (9012)
Thread Start: Thread ID: 476. Process regindoc.exe (9012)
Thread Start: Thread ID: 13340. Process regindoc.exe (9012)
Module Load: Windows.StateRepositoryPS.dll. No Debug Info. Base Address: $64CA0000. Process regindoc.exe (9012)
Thread Exit: Thread ID: 3028. Process regindoc.exe (9012)

But I do not see that it was loaded TBMAPI. Or here also does not show?
Branch in CURRENT_USER empty, and any different response at branch change in LOCAL_MACHINE

12

Re: MapiSendMailW in Windows 10

Broad gull it is necessary to look at least after call MAPISendMailW. Define and still, at you the provider or 64 bit is active 32 bit MAPI?

13

Re: MapiSendMailW in Windows 10

Aniskin, yes, at us 7.1...
But then questions smile
Why the ordinary function with PAnsiChar MAPISendMail earlier worked, and now is not present.
Why now does not work both Thunder, and Outlook even with MAPISendMailW.
And if only at me it was covered... And that was covered three machines and after update.
And not only my program, but also others which as opened dialogues.
Did not find that still someone complained, something means at me sad
Windows 64. Bath costs 64. It tbmapi64.dll also specified (but tried and 32). The program 32.
But  it is not necessary to consider this question, because worked earlier smile At the same .

14

Re: MapiSendMailW in Windows 10

Devillio wrote:

Why the ordinary function with PAnsiChar MAPISendMail earlier worked, and now is not present.
Why now does not work both Thunder, and Outlook even with MAPISendMailW.

Because where that at whom that that changed in a surrounding.

Devillio wrote:

And if only at me it was covered... And that was covered three machines and after update.

At me Win10 with all updates, all both worked, and works.

Devillio wrote:

did not find that still someone complained, something means at me sad

Debagger in hands and to study that at you.

Devillio wrote:

Windows 64. Bath costs 64. It tbmapi64.dll also specified (but tried and 32). The program 32. The program 32. But  this question consider not it is necessary

32 bit programs can use only 32 bit MAPI the provider. 64 bit programs can use only 64 bit MAPI the provider. Accordingly, if at you 32 bit program the provider should be installed 64 bit MAPI. But if you consider it not essential , I am eliminated.

15

Re: MapiSendMailW in Windows 10

* Accordingly, if at you 32 bit program the provider * should be installed 32 bit MAPI

16

Re: MapiSendMailW in Windows 10

Aniskin, I thank for the help.
Delivered on "pure" Windows all (there all went), noted that in the register mail application by default is underlined in a branch "CURRENT_USER", and descriptions of mail programs - in "LOCAL_MACHINE". Still took down 64 Bath, in the register did changeovers on bat32 - and all went!
I.e. as though "32 bit MAPI the provider" is installed, if your words.
For check the application  for a platform x64 - as all works. So I do not know)) should plow and and so, and logically too - and differently in all Windows this function will be accessible either 32, or 64, and owe to all.
So the problem was, seemingly, in instructions layout on application by default.
Litter for a topic in Delphi, the problem appeared not texts)))
Once again I thank all for the help!

17

Re: MapiSendMailW in Windows 10

Devillio wrote:

should plow and and so, and logically too - and differently in all Windows this function will be accessible either 32, or 64, and owe to all.

I apologize, I absolutely forgot that MAPISendMail is an exception and for it Windows creates proxy process.
https://msdn.microsoft.com/en-us/librar … 41355.aspx

18

Re: MapiSendMailW in Windows 10

https://msdn.microsoft.com/en-us/library/dd296734 (v=vs.85).aspx
The use of Simple MAPI is discouraged. It may be altered or unavailable in subsequent versions of Windows
Somehow so...