The documentation at nc-mapi-mapisendmail says "On Windows 8 and later: Call MAPISendMailW to send a message." Have you tried this?
MAPI error MAPI_E_NOT_SUPPORTED problem
Hello everybody!
My working environment is: Windows 10, Visual Studio Community 2017 (and 2008 for older projects), programming takes place only in C/C++.
I need my program to be able to send emails with a PDF file attachment. The easiest way to send emails is to use ShellExecute with the parameter "mailto:someone@Monique gmx .com ... etc". But this method does not allow you to transfer attachments.
So I tried using MAPI library's MAPISendMail function in a variety of variants found on the internet. Including Programmatically adding attachments to emails and many others. Almost all of them work fine on my computer.
However, when I trying to send an email on another computer, it leads to an error in the MAPISendMail function MAPI_E_NOT_SUPPORTED (code 26). In this case, the MAPILogon function is executed without errors. Both computers, mine and the other, are on the same network and use the same mail server and Outlook as the client for users. On the other computer manual send/receive of the emails works perfectly. I searched the Internet for a long time for an explanation of this error, but found nothing.
Please explain me what this error means and how to fix it. Why is it that under the same conditions, in the same environment, on two different computers, mail is sent normally on one computer, and an error occurs on the other?
Thank you very much!
Regards, Jurgis.
Windows development | Windows API - Win32
3 answers
Sort by: Most helpful
-
-
Jurgis Armanavichius 1 Reputation point
2022-09-13T06:20:29.493+00:00 Yes, I am calling this function, but its ANSI version. My message and subject are encoded in ANSI. Do you mean that I need to call the UNICODE version?
My code fragment:hMAPI = ::LoadLibrary("mapi32.dll"); lpfnMAPISendMail = (LPMAPISENDMAIL)::GetProcAddress(hMAPI, "MAPISendMail"); lpfnMAPILogOn = (LPMAPILOGON)::GetProcAddress(hMAPI, "MAPILogon"); lpfnMAPILogOff = (LPMAPILOGOFF)::GetProcAddress(hMAPI, "MAPILogoff"); ... MapiRecipDesc recipient[1] = { 0 }; recipient[0].ulRecipClass = MAPI_TO; recipient[0].lpszAddress = szTo; // "SMTP:******@mail.com" recipient[0].lpszName = szNameTo; // "User" MapiFileDesc MAPIfile[1] = { 0 }; MAPIfile[0].nPosition = 0xFFFFFFFF; MAPIfile[0].lpszPathName = szFullAttachFileName; // "C:\work\attachment.txt" MAPIfile[0].lpszFileName = ""; // File name will be retrieved automatically MapiMessage MAPImsg = { 0 }; MAPImsg.lpszSubject = "Test message" MAPImsg.lpRecips = recipient; MAPImsg.nRecipCount = 1; MAPImsg.lpFiles = MAPIfile; MAPImsg.nFileCount = 1; MAPImsg.lpszNoteText = "This is the test message"; LHANDLE lhSession = NULL; ULONG nLog = lpfnMAPILogOn(0, NULL, NULL, MAPI_NEW_SESSION, 0, &lhSession); if( nLog != SUCCESS_SUCCESS ) { // Try MAPI_LOGON_UI nLog = lpfnMAPILogOn(0, NULL, NULL, MAPI_LOGON_UI, 0, &lhSession); } // Send message FLAGS flFlags = MAPI_DIALOG; ULONG nSent = lpfnMAPISendMail(lhSession, (ULONG_PTR)HWND_DESKTOP, &MAPImsg, flFlags, 0); if( nLog == SUCCESS_SUCCESS ) { lpfnMAPILogOff(lhSession, 0, 0, 0); } ::FreeLibrary(hMAPI);
I omitted error checking for code shortness. MAPILogOn completes without errors. But MAPISendMail returns an error MAPI_E_NOT_SUPPORTED (code 26) if I run the program on another computer. At the same time, everything runs without errors on my computer. So I want to understand what this error 26 means?
Please help me! Thank you very much!
Regards, Jurgis.
-
Jurgis Armanavichius 1 Reputation point
2022-09-14T07:11:47.97+00:00 I made a UNICODE version of the program. Nothing has changed. The error remained exactly the same.
It is especially unclear why this error is not on my computer (both in the UNICODE version and in the ANSI version), but it is on another computer that runs in exactly the same environment? As I mentioned earlier, both computers, mine and the other, are on the same network, use the same Windows 10, and use the same mail server and Outlook as an email client for users.
How do I understand what the MAPI_E_NOT_SUPPORTED error (code 26) means? If this could be understood, then this error would not be difficult to correct.
Please help me! Thank you very much!
Regards, Jurgis.