Jump to content
Dany Marmur

Q for MAPI Expert

Recommended Posts

In Winapi.MAPI there is the InitMapi method called before a lot of operations.

I have traced into that method from TSendMail.Execute.

The method tries to read some registry keys but fails.


I have checked another MAPI implementation i have access to, the one in madExcept.

That exact registry check can be found there to, but it's commented out (!).


I have been googling but there's so much noise!


Is it a VCL (Vcl.ExtActns/Winapi.MAPI units) bug?





Share this post

Link to post

It seems newer Windows installations (?) does not have that registry value:


InitMapi @445


      if RegQueryValueEx(hkWMS, 'MAPI', nil, @rType, @MAPIValueBuf,
        @MAPIValueSize) <> ERROR_SUCCESS then Exit;

Always fails, so nothing happens.

Share this post

Link to post

Looks much cleaner than other implementations.

I'll keep fiddling with this.




Share this post

Link to post

IMHO, you implementation is much more readable.

I have successfully managed to have Outlook throw up a mail dialog with a HTML body 🙂

I do not think (except for the VCL registry check) that the other implementations are worse but it was easier to try different things using your unit. Thanks!


Aside; I'm still a bit confused; on the net most posts states that you cannot do formatted mails with Simple MAPI.

It should be possible with Extended MAPI. Perhaps there's three APIs?

Anyways the "Simple MAPI Trick" to attach only one the html file seems to work.

Share this post

Link to post
Posted (edited)

I'm glad if it works. I don't know every implementation but I could not find any which supports unicode for example, so I made my own.

Also, you can have multiple attachments.


Edited by Attila Kovacs

Share this post

Link to post
On 3/20/2021 at 1:37 PM, Attila Kovacs said:

Use it as you want if it works.

I'd be happy if fixes/enhancements would come back to me! 😉


Thank you for the unit!


I have found a bug regarding attachments in mvAnsi mode (two times there should be TMapiFileDesc instead of TMapiFileDescW; ^ is missing in FillChar).


Original code:

      if LAttachCount > 0 then
        GetMem(LAttachments, SizeOf(TMapiFileDescW) * LAttachCount);
        FillChar(LAttachments, SizeOf(TMapiFileDescW) * LAttachCount, 0);


Please change to:

      if LAttachCount > 0 then
        GetMem(LAttachments, SizeOf(TMapiFileDesc) * LAttachCount);
        FillChar(LAttachments^, SizeOf(TMapiFileDesc) * LAttachCount, 0);


I have also added a simple procedure SetMapiDll (on clients computers, GroupWise is installed and used. Outlook 2019, which is also installed, but not used, keeps overwriting the registry entry, so I will probably have to load directly C:\Program Files (x86)\Novell\GroupWise\gwmlt1.dll there).

procedure SetMapiDll(const AMapiDll: string);


  • Like 2

Share this post

Link to post
On 5/24/2021 at 9:48 PM, Attila Kovacs said:

@Vandrovnik Thank you for pointing that out!

There is another small one (missing "W"), which probably makes no problem now:

in mwWide, original code:

      FillChar(LMapiMessageW, SizeOf(LMapiMessage), 0);

please change to

      FillChar(LMapiMessageW, SizeOf(LMapiMessageW), 0);


  • Like 1

Share this post

Link to post
9 hours ago, Vandrovnik said:

Emba could also repair their implementation...

They won't as MAPI is officially discontinued. I'll put it on github though.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now