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

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Traditional approaches to application modernization, either manual rewrite or auto-migration tools, have been proven time and again as inefficient. Rewrite needs scarce dev skills, is slow, risky and costly; auto-migration is what Verccio Dale of Gartner defines as "a pig with a lipstick, is still a pig." Are there alternatives? Find out, download this short practical guide now!

Most Popular Programming Stories

More for Developers

RSS Feeds

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