TMailer does not work if the application bitness differs from Outlook
Borland's Object Windows Library for the modern age
Brought to you by:
jogybl,
sebas_ledesma
Note: under the hood TMailer uses the MAPISendDocuments function which is marked as "The use of this function is discouraged. It may be altered or unavailable in subsequent versions of Windows."
With the pending deprecation of classic Outlook and move to New Outlook, which does not support MAPI, this class may no longer be depended on in the future.
Note: The fix can be backported to the 7 and 6.44 branches, but it may bot be worth it if noone is actually using the TMailer code - and if they do, they should have already implemented their own checks for MAPI availability.
@jogybl, regarding your patch [r8753]:
This fix is very Outlook-centric and will, if I'm not mistaken, exclude users (like me) that have an alternative MAPI-compliant client on their system, e.g. ThunderBird.
With the help of AI, I have researched the "bitness" issue a little, and it seems that parts of MAPI are better supported than others. In particular, MAPISendMailW has no deprecation warning and even has special handling with regards to this finicky "bitness" issue.
See: Building MAPI applications on 32-bit and 64-bit platforms
Hence, as a better solution than disabling MAPI for all but a select group of Outlook users, I propose that you instead redirect calls to MAPISendMail when MAPISendDocuments fails with error code E_FAIL (0x80004005) and last error is ERROR_PROC_NOT_FOUND (0x7F).
The attached patch does just that. It also documents TMailer::SendDocuments as deprecated and recommends the new function TMailer::SendMail instead. The latter has a convenient C++-style signature (const TWindow* owner, const tstring& subject, const tstring& message, TAttachments = {}). The optional last argument specifies a list of files to be sent with the message, making it very easy to switch to using this function instead of SendDocuments.
I've tested the new SendMail as well as the redirected SendDocuments in RichEditor, and both seem to work very well with my MAPI client (ThunderBird).
Edit: For the records, this patch has now been applied [r8920], superseding [r8753].
Related
Commit: [r8753]
Commit: [r8920]
Last edit: Vidar Hasfjord 2026-09-30
I tested the patch, and it is definitely an improvement - now both the 32-bit and the 64-bit builds of RichEdit can send mail - previously only the 64-bit build worked on my system.
I also tried it on two other machines, one that has Thunderbird and New Outlook installed, and another that has only New Outlook outlook installed, and on both it reports an error "There is no email program associated ..." and then "MAPISendMailW failed, error: 2"
I guess that the MAPI functionality required classic Outlook to be installed.
P.S. Thunderbird is my favorite email client, I keep Outlook only for some work-related purposes.
@jogybl wrote:
Great to hear your testing validates the patch!
Regarding the system with Thunderbird on it, you could presumably configure Thunderbird to be the standard MAPI client and have it working, considering that this works fine on my system. For good measure, I just tested 32-bit as well here, and it works fine, in both ANSI and UNICODE builds.
Right, I made sure that Thunderbird is the default email application and the Send function worked.
The latest changes fail to compile with Embarcadero C++ Builder with the error
according to the MAPISendDocuments documentation, the return type is
ULONGand the failure code isMAPI_E_FAILURE(2).For a quick fix I added a cast, and also the MAPI_E_FAILURE case in [r8935].
Related
Commit: [r8935]