Virtual Developer Workshop: Containerized Development with Docker

Here is a simple CMapi Class to help developers configure an Exchange Profile. By using this class

you can:

  • Add/Delete Microsoft Exchange Profiles
  • Configure Microsof t Exchange Profiles
  • Add/Delete Microsoft Exchange Messaging Services
    • Exchange
    • MS Mail
    • Lotus
    • Personal Folders
    • Personal Address Books
    • Outlook Address Books
  • Configure Message Services (Server name, User name)
  • Set Default Messaging Stores (i.e. Setting the Exchange Mailbox as the Default Messaging Store)

The project that is included is basically a simple dialog box that will show the progress of the wizard. To use run the project you will need to have an Exchange box on the network. Supply the Exchange server name in the code below and make sure you have the user name correct. When you run this app it will attempt to connect to the server when it tries to configure the messaging service parts and set the default messaging stores. If the username is not correct, it will stop. So verify the format that your Exchange server users for names (i.e. Last Name, First Name OR First Name Last Name). This application has been tested with Microsoft Windows NT 4.0 and Microsoft Visual C++ 6.0. Please don't forget to include MAPI32.LIB in the linker tab! Please feel free to modify this code. This code is a good starting point for anyone who is going to be doing any MAPI code - and there is some extra code that you can add (you find it!) for some cool MAPI coding.

All the actual code is in the OnStart() Function - Please note that this code does NOT create a NEW Microsoft Exchange Profile, it uses the default profile (MAPI_USE_DEFAULT) - but this can easily be changed...

  void CProfileDemoDlg::OnStart() 
      CMapi Mapi;
      // Look in MAPISVC.INF for Service names (i.e. MSEMS)
      LPSTR lpszAddService = "MSEMS", // Microsoft Exchange Service to Add (in this case Exchange)
          lpszDelService = "MSFS", // Microsoft Exchange Service to Delete (in this case MSMAIL)
          lpszServiceName = "Microsoft Exchange Server", // Exchange Service Official Name
          lpszMailbox = "Christopher Backen", // Person to Configure
          lpszMailStore = "Mailbox - Christopher Backen", // Message Store to Configure
          lpszServerName = "CORDALEX1"; // Server to Configure
      // Set Progress Bar 
      m_pBar.SetRange(0, 10);
      // Start the session
      m_Info.SetWindowText("Initializing MAPI Dynamic Link Library");
      hr = Mapi.Initialize();
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      hr = Mapi.AdminProfiles();
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_Info.SetWindowText("Logging on to the Default Profile");
      hr = Mapi.LogonDefaultEx();
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;} 
      hr = Mapi.OpenAdminServices();
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_Info.SetWindowText("Creating Microsoft Exchange Messaging Service");
      hr = Mapi.CreateMessagingService(lpszAddService, lpszServiceName);
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_Info.SetWindowText("Configuring Microsoft Exchange Messaging Service");
      hr = Mapi.ConfigureMessagingService(lpszAddService, lpszMailbox, lpszServerName);
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_Info.SetWindowText("Deleting Microsoft Mail Messaging Service");
      hr = Mapi.DeleteMessagingService(lpszDelService);
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;} 
      hr = Mapi.GetMessageStoresTable();
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_Info.SetWindowText("Setting the default mailbox to the server");
      // More complex
      hr = Mapi.SetDefaultMessagingStore(lpszMailStore);
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      // DONE

To find any service names - consult the MAPISVC.INF file. For Example:

 MSEMS=Microsoft Exchange Server <--- Here is the name of the Exchange Service 
 IMAIL=Internet E-mail
 MSPST AB=Personal Address Book
 MSPST MS=Personal Folders
 MSFS=Microsoft Mail
 CONTAB=Outlook Address Book
 MSN=The Microsoft Network Online Service
 [Default Services]
 MSEMS=Microsoft Exchange Server
 MSPST AB=Personal Address Book

 ....Blah Blah Blah

This code really helped my group. I hope it helps you out just as much. If you have any comments or suggestions please send them to the above address. Or visit VIZ Group AppDev Division.

ProfileDemo.zip - 33 KB

CMapi Class (Mapi.h) - 3 KB


  • Unresolved Name

    Posted by Legacy on 04/17/2001 07:00am

    Originally posted by: Eitan Michaelson

    Does anyone here know how to create the profile (with exchange service provider) offline ,
    without MAPI automatically resolving server\user names ?


    can u help ?

  • Possible Answer for below problems

    Posted by Legacy on 04/12/2000 07:00am

    Originally posted by: Mohammad S. Ronosentono

    This is probably because of Outlook 98 since Outlook 98 doesn't use profile any longer. Try using Outlook 97 since it's still using profile to login.

    If the application run as a service then you need to set user account and password in the service before running it. Hopefully, it will work.

  • Same problem as below

    Posted by Legacy on 07/27/1999 07:00am

    Originally posted by: Hunter Hoyt

    I'm using Outlook 98 and I can't get it to work. It has to do something with the "CreateMsgService" MAPI function. I'm on a network too. Also, I want to use this code in one of my programs that is registered as a service. Will this be possible?

  • MAPIInitialize fails with "Unknown Error"!

    Posted by Legacy on 05/30/1999 07:00am

    Originally posted by: Kamran Ansari

    I have not been able to use this sample on my PC. I have
    Outlook 98 client installed on my PC, which is on a network with
    MS-Exchange box (also on the network).

    When I run the sample, MAPIInitialize () fails with an unknown
    error. This happens even with the Microsoft's extended MAPI
    sample app. Is there something wrong with my set-up? Please

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date