This page has been archived and is no longer  being actively maintained.
Outlook Developer Home
Outlook Programmer's Library
 
Outlook Technologies
Outlook Forms
Languages
Samples
Other Technologies

 

To convert incoming HTML messages to plain text or Rich Text format

Many people do not like to receive messages in HTML format because the messages take up more space in the Inbox than plain text messages and trigger dialups to the Internet if they contain links to Internet images, including "web bugs" used to track message and ad viewing.

Outlook 2003 includes features to block "web bugs" and convert all incoming HTML mail to plain text. Outlook 2000 SR-1 and Outlook 2002 also have the "read as plain text" feature; see OL2002 Users Can Read Nonsecure E-mail As Plain Text for details. This features can affect custom applications, however. 

The code samples here demonstrate various methods for converting HTML messages into either plain text or rich text using a rule in Outlook 2002, VBA application-level code, or an on-demand VBA macro. They also serve as examples of all those different ways to process incoming messages.

For those who don't want to write code, several tools to scrub HTML are also available.

Outlook 2002 and later | Outlook 2000 CW Mode | Outlook 2000 IMO Mode | Notes | Tools | More Information

Outlook 2002 and Later Code Sample

Starting with Outlook 2002, you can call a VBA subroutine from a Rules Wizard rule using the "run a script" rule action. The procedure can be in either the built-in ThisOutlookSession module or any custom module and must include a MailItem or MeetingItem argument. This short example converts all incoming messages to plain text:

 

The other Outlook 2002 (or later) feature that makes this work is the BodyFormat property of the MailItem object, which allows you to set a message's format. Note that changing a message from HTML to plain text makes any embedded image attachments inaccessible from the user interface. They are still stored in the message, however, and can be accessed via code.

We have not done any testing to see how well the "run a script" rule holds up when the user receives hundreds of messages at one time.

NOTE: To avoid security prompts when accessing properties like Body and Recipients, you must use the technique above to get the item indirectly, through its EntryID property and the Namespace.GetItemFromID method. If you attempt to access MyMail.Body or MyMail.SenderName, for example (MyMail being the name of the parameter for the "run a script" rule procedure), you will get a security prompt.

WARNING: We have seen a couple of instances where a machine running Outlook 2002 with such a rule completely loses the VbaProject.otm file that contains all the Outlook VBA code. If you use "run a script" rules, be sure to back up VbaProject.otm regularly or export the individual modules.

This type of rule apparently should not be run by Exchange Server users working offline. See OL2002 Error Message The Message You Specified Could Not Be Found When You Synchronize.

Also see:

Outlook 2000 CW Mode Code Sample

This VBA code sample for Outlook 2000 removes all HTML tags from new items arriving in the Inbox and saves them in RTF format. It needs to run in the built-in ThisOutlookSession module.

CAUTION: We recommend that you use this technique only if you are running Outlook 2000 in Corporate/Workgroup mode. If you use it in Internet Mail Only mode, your replies will also be in Rich Text format, which most Internet mail users (at least those not using Outlook) cannot read. They will get a mysterious Winmail.dat attachment, and any normal file attachments you send will be indecipherable.

 

This sample monitors only the Inbox folder. You could do much the same thing with other folders by adding code to do the following:

  • Declare an Items collection object for each folder WithEvents
  • Instantiate the Items collection object in the Application_Startup event handler
  • Add an ItemAdd event handler for the Items collection object

If the incoming HTML-format message contains any background or embedded images, these appear as attachments in the RTF-format message.Back to Top

Outlook 2000 IMO Mode Code Sample

Outlook MVP Neo offers this variation for Outlook 2000 running in Internet Mail Only mode, to remove the HTML content from the currently selected item using CDO. (Because CDO does not install automatically, you may need to rerun Outlook setup to add it).

If you want to run StripHTML automatically against all incoming items, then you'll need to use the same events as for the CW version above, but modify both the ItemAdd event handler and the StripHTML code to perform the removal on the Item that ItemAdd passes, rather than on the selected item.

 Back to Top

Notes

In Outlook 2000, setting the Item.Body property automatically makes the format Rich Text (despite what the Help file says about it forcing the format to the user's default choice; that's an error in Help). Similarly, setting the Item.HTMLBody property would convert the item to HTML format automatically.

Starting with Outlook 2002, setting the Item.Body property really does convert the format to the user's default, and you can use the BodyFormat property to directly set the format of a message. Back to Top

Tools

Attachment Options Outlook COM add-in that sets the Read as Plain Text option.
Email Not HTML POP mail download program that removes HTML content and embedded files (retained as one or more attachments) from a message before Outlook opens it. Also zips any attachments that aren't already zipped. Can be set to leave only "safe" HTML in the message.
NoHTML Outlook COM add-in that works much like the ZapHTML code above, stripping HTML content as a user switches from one message to another.
PocketKnife Peek Outlook  add-in to allow you to read the plain text version, HTML source, or Internet headers of any incoming message, all from one tabbed interface. Also includes a "Reply to Some" feature to generate a reply to selected recipients (fewer than "Reply to All"). Free for personal use.
Watch Your Back Tool to strip HTML content and manage read receipts in incoming messages.  Back to Top

More Information

   
© 2002-6 TurtleFlock, LLC
All right reserved.
About OutlookCode.com

Send comments to webmaster@outlookcode.com

Designed and Implemented by TerraLink USA 

FrontPage Integration
by RobsonDesignWorks

 
 
get Sue's code | forums | share your own code | registration