Run MAPI as a Windows Service with AlwaysUp

How to Run a MAPI Application as a Windows Service with AlwaysUp

Start sending email from your Extended MAPI program as soon as your PC boots, before any one logs on. Keep it running 24x7!

Microsoft's Messaging Application Programming Interface (MAPI) allows Windows applications to send and receive email.

To configure a MAPI-enabled application with AlwaysUp:

  1. First, you must prepare your MAPI code to operate properly when run in the context of a Windows Service. We suggest the following changes:

    1. Initialize MAPI for use in a service by specifying MAPI_NT_SERVICE to MAPIInitialize. For example:

      
        MAPIINIT_0 MAPIINIT = { 0, MAPI_NT_SERVICE };
        hRes = MAPIInitialize(&MAPIINIT);
      
      

    2. Call MAPILogonEx with the MAPI_NT_SERVICE flag, for example:

      
        flFlags = MAPI_NEW_SESSION | MAPI_EXTENDED | MAPI_NT_SERVICE
      			 | MAPI_LOGON_UI;
        hRes = MAPILogonEx(
      	0L,                    // Handle to parent window or 0.
      	lpszProfileName,       // Default profile name.
      	lpszPassword,          // User password for MAPI session.
      	flFlags,               // Various session settings
      	&ses                   // Return handle to MAPI Session
        );
      
      

    Note: If you would like your program to continue to operate normally outside of a Windows Service, we recommend using a command line flag to identify when running as a service and changing the code to react accordingly. For example, our sample application (configured below) only invokes the above changes when it is passed the /RunService flag on the command line.

  2. Download and install AlwaysUp, if necessary.

  3. Start AlwaysUp.

  4. Select Application > Add to open the Add Application window:

    Add Application

  5. On the General tab:

    • In the Application field, enter the full path to your MAPI executable. We'll specify our sample application in:

      C:\MAPI\MAPIServer.exe

    • In the Name field, enter the name that you will call the application in AlwaysUp. We have used MAPI Server but you can specify almost anything you like.

    • If your executable needs one or more arguments, enter them in the Arguments field. Our sample application will take /RunService, to tell it to initialize MAPI as in step 1.

    MAPI Application Windows Service: General Tab

  6. Click over to the Logon tab and enter the user name and password of the account in which you installed and configured your MAPI application.

    MAPI Application Windows Service: LogOn Tab

  7. Click over to the Startup tab and check the Ensure that the Windows Networking components have started box. This informs AlwaysUp that the MAPI application needs TCP/IP networking support to do its work.

    MAPI Application Windows Service: Startup Tab

  8. Click the Save button. In a couple of seconds, an application called MAPI Server will show up in the AlwaysUp window. It is not yet running though.

    MAPI Application Windows Service: Created

  9. To start the server choose Application > Start "MAPI Server". On Windows 7, 2008 or Vista (or when connecting via RDP), you will have to choose Application > Start "MAPI Server" in this Session if you wish to show your application's windows. (More on this in the AlwaysUp FAQ.)

    MAPI Application running as a Service with AlwaysUp

  10. That's it! Next time your computer boots, your MAPI application will start up immediately, before anyone logs on. We encourage you to edit the entry in AlwaysUp and check out the many other settings that may be appropriate for your environment.



MAPI Application not working properly as a Windows Service?

  • From AlwaysUp, select Application > Report Activity > Today... to bring up a HTML report detailing the interaction between AlwaysUp and your application. The AlwaysUp Event Log Messages page explains the more obscure messages.
  • Running a MAPI application unattended can be tricky, especially if it throws up dialog boxes and other windows that interrupt the action. If these can not be eliminated you may want to investigate using an automation script/program to automatically dismiss the pesky windows. Please see the Automate tab (or the AlwaysUp User's Manual) for additional information on automation with AlwaysUp.
  • See "How To MAPI Enable a Windows NT Service" for a discussion on other issues when running as a service.
  • Consult the AlwaysUp FAQ for answers to commonly asked questions and troubleshooting tips.
  • Contact us and we will be happy to help!

Download & Try it Free!

Download AlwaysUp and Run as a Service Today! Version 15.5 New!

8.0 MB Installer
Our 12,000+ customers include...
Compatible with Windows 11 Compatible with Windows Server 2022 Compatible with Windows 10
Over 94,000 installations, and counting!
 
AlwaysUp is number 1! Run as a Service with AlwaysUp

Rock-solid for the past 19+ years!