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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds