HOWTO: Print Messages in Rich Text Using Outlook Object Model

ID: Q179084


The information in this article applies to:


SUMMARY

A fairly common request of a messaging application is to print an e-mail message in Rich Text Format (.rtf). This article describes how to use the Outlook object model to accomplish this task.


MORE INFORMATION

Because Messaging Application Programming Interface (MAPI) stores .rtf files in a compressed format in the PR_RTF_COMPRESSED field in a message, it is not possible to print just the contents of the field and get any meaningful results.

Printing a message in its original Rich Text Format is not possible for Collaboration Data Objects (CDO) without calling custom extensions. Please see the article listed in the REFERENCES section for more information.

The other alternative is to use Extended MAPI, which unfortunately is not available to Visual Basic developers due to language limitations.

The Exchange Appfarm includes a sample called ExPrint in the Misc Tools section. ExPrint automatically prints a new incoming message, but will apply its own formatting to the message content. Build the code sample below into an .exe file and use it in place of the Visual Basic .exe file that ExPrint instructs you to execute. Please refer to the REFERENCES section for the location of the sample.

The following code sample demonstrates a process that you can use to print not only your e-mail messages, but also any attachments (as long as they have a registered OLE Server on the system) in their original rich-text format.

Sample Code


'This code sample assumes a reference to the
   'Outlook object model (MSOUTL8.OLB).
   Dim myOlApp As Object
   Dim olNameSpace As Object
   Dim myItem As Object


   Sub Main()
      Set myOlApp = CreateObject("Outlook.Application")
      Set olNameSpace = myOlApp.GetNamespace("MAPI")
      Set myItem = olNameSpace.GetItemFromID(Command)


      myItem.Display
      myItem.PrintOut
      myItem.Close 1

   End Sub 


REFERENCES

For additional information about how to use Extended MAPI to allow RTF-formatting in a message created by Active Messaging, please see the following article(s) in the Microsoft Knowledge Base:

Q172038 FILE: DLL to Read and Write RTF with Active Messaging
To obtain the ExPrint sample, please see the following Web site:
http://technet.microsoft.com/cdonline/content/complete/boes/bo/mailexch/exch/tools/appfarm/misctool/exprint.htm

Additional query words: ActMsg


Keywords          : 
Version           : WINDOWS:4.0,5.0,8.03
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: March 29, 1999