Menu β–Ύ β–΄

#640 TMailer does not work if the application bitness differs from Outlook

8
pending
None
1
2026-10-06
2026-03-30
No

If a 32-bit application is trying to use TMailer class to send emails, but the installed Outlook is 64-bit (or vice-versa), the call fails with error 2147500037 - The specified procedure could not be found.

This can be demonstrated in the RichEdit example by using the Send menu item.

Maybe TMailer::IsMAPIAvailable should check is the application and Outlook bitness match and return false otherwise.

Discussion

  • Ognyan Chernokozhev

    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.

     
  • Ognyan Chernokozhev

    • assigned_to: Ognyan Chernokozhev
    • Group: unspecified --> 8
     
  • Ognyan Chernokozhev

    • status: open --> pending
     
  • Ognyan Chernokozhev

    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.

     
  • Vidar Hasfjord

    Vidar Hasfjord - 2026-09-29

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

    [MAPISendDocuments is marked as deprecated in the documentation]

    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
    • Ognyan Chernokozhev

      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.

       
      πŸ‘
      1
  • Vidar Hasfjord

    Vidar Hasfjord - 2026-10-01

    @jogybl wrote:

    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

    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.

     
    • Ognyan Chernokozhev

      Right, I made sure that Thunderbird is the default email application and the Send function worked.

       
      πŸ‘
      1
  • Ognyan Chernokozhev

    The latest changes fail to compile with Embarcadero C++ Builder with the error

    1>   ..\..\source\owlcore\mailer.cpp(88,10): error E5356: case value evaluates to -2147467259, which cannot be narrowed to type 'unsigned long' [-Wc++11-narrowing] [C:\Work\OWLNext\Subversion\trunk\build\embarcadero\owl.cbproj]
    

    according to the MAPISendDocuments documentation, the return type is ULONG and the failure code is MAPI_E_FAILURE (2).

     
    • Ognyan Chernokozhev

      For a quick fix I added a cast, and also the MAPI_E_FAILURE case in [r8935].

       

      Related

      Commit: [r8935]


Log in to post a comment.