Microsoft KB Archive/187822

From BetaArchive Wiki
Knowledge Base


PRB: MAPILogon fails with error 3 called from CGI script on IIS

Article ID: 187822

Article Last Modified on 8/18/2005



APPLIES TO

  • Simple Messaging Application Programming Interface (MAPI)



This article was previously published under Q187822

SYMPTOMS

The MAPILogon() function returns error code 3 (MAPI_LOGIN_FAILURE) when called from within a Common Gateway Interface (CGI) script, written in C or C++, and running under Microsoft Internet Information Server (IIS).

CAUSE

The MAPILogon function requires a valid MAPI profile to operate. Processes that run as Windows NT services do not have default access to the HKEY_CURRENT_USER registry hive, where the MAPI profile information is stored, so MAPILogon cannot get to the profile to use it.

Additionally, it is necessary to specify an Exchange Server mailbox in a MAPI profile. Because CGI scripts usually log on to Windows NT as LocalSystem, and that account cannot be associated with an Exchange Mailbox, creating a profile programmatically from the CGI script also does not work.

RESOLUTION

To work around the CGI limitation, try this approach:

  1. Write the CGI script so that it writes the e-mail message information to a file.
  2. Use another program, running as a Windows NT service, to read the file and send the e-mail.

This service would log on to the domain with a valid Windows NT user account, create a profile on the fly, then log on to its Exchange mailbox and send mail. To accomplish this, modify the MSDN NTSERVICE sample by adding Simple MAPI code sufficient to send e-mail. For more information, please see the Microsoft Developer Network article "Creating a Simple Windows NT Service in C++."

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

173550 How to use VC++ to start a CDO (1.x) session


170225 How to modify settings of MS Exchange Transport Provider



Additional query words: kbDSupport kbdse cgi mapilogon kbMsg kbMAPI kbMAPI000

Keywords: kbprb KB187822