MAPI Class '& Simple MAPI Project

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);
      m_pBar.SetStep(1); 
      
      // 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_pBar.SetPos(2); 
      
      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_pBar.SetPos(4); 
      
      m_Info.SetWindowText("Creating Microsoft Exchange Messaging Service");
      hr = Mapi.CreateMessagingService(lpszAddService, lpszServiceName);
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_pBar.SetPos(5); 
      
      m_Info.SetWindowText("Configuring Microsoft Exchange Messaging Service");
      hr = Mapi.ConfigureMessagingService(lpszAddService, lpszMailbox, lpszServerName);
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_pBar.SetPos(6); 
      
      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_pBar.SetPos(8); 
      
      m_Info.SetWindowText("Setting the default mailbox to the server");
      // More complex
      
      hr = Mapi.SetDefaultMessagingStore(lpszMailStore);
      if (HR_FAILED(hr)){ AfxMessageBox("Failed..."); return;}
      m_pBar.SetPos(9); 
      
      Mapi.CloseMapi();
      
      m_pBar.SetPos(10); 
      
      // DONE
      return; 
  } 

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

[MAPI]
 ServiceOrder=AWFAX,MSEMS,MSFS,IMAIL,MSN
 [Services]
 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
 [MSEMS]

 ....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



Comments

  • Unresolved Name

    Posted by Legacy on 04/17/2001 12: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 ?

    I guess I should not use PR_PROFILE_UNRESOLVED_NAME & PR_PROFILE_UNRESOLVED_SERVER

    can u help ?

    Reply
  • Possible Answer for below problems

    Posted by Legacy on 04/12/2000 12: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.

    Reply
  • Same problem as below

    Posted by Legacy on 07/27/1999 12: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?

    Reply
  • MAPIInitialize fails with "Unknown Error"!

    Posted by Legacy on 05/30/1999 12: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
    help!!

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

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • You probably have several goals for your patient portal of choice. Is "community" one of them? With a bevy of vendors offering portal solutions, it can be challenging for a hospital to know where to start. Fortunately, YourCareCommunity helps ease the decision-making process. Read this white paper to learn more. "3 Ways Clinicians can Leverage a Patient Portal to Craft a Healthcare Community" is a published document owned by www.medhost.com

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds