PRB: MAPILogon Fails with Error 3 Called from CGI Script on IIS

ID: Q187822

The information in this article applies to:

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 additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q173550
   TITLE     : HOWTO: Using VC++ to Start an Active Messaging Session

Additional query words: kbDSupport kbdse cgi mapilogon kbMsg kbMAPI kbMAPI000
Version           : WINDOWS:1.0
Platform          : WINDOWS
Issue type        : kbprb

Last Reviewed: August 13, 1998