Exchange Messaging Outlook
Volume 10, Number 20

 
Greetings! Welcome to Vol. 10, No. 20, Jan 19, 2006, of Exchange Messaging Outlook, a biweekly newsletter about Microsoft Exchange and Microsoft Outlook.

Today's highlights:

Regular features:

Processing Incoming E-mails with Macros

By Eric Legault, Microsoft MVP

The Rules Wizard is great for a lot of things when automatically processing incoming e-mails. However, when there's that one certain thing that you can't do with it, you can always be the Wizard yourself and write your own rules with VBA. However, one of the greatest challenges for developers programming with Outlook is learning how to effectively hook into application events. While it is relatively easy to gain access to objects on the fly, it is not entirely obvious where, when or how these objects should be managed. If Outlook automation was anything like most object models, it would be very straightforward.
Imagine this "fantasy" code:

Sub WorkWithNewMail()

Dim objOutlook As Outlook.Application
Dim objAllNewMail As Outlook.Items
Dim objMyEmail As Outlook.MailItem
Set objOutlook = New Outlook.Application
Set objAllNewMail = objOutlook.NewMail
For Each objMyEmail In objAllNewMail
'Do something with every e-mail received
Next

Next

End Sub

Wouldn't this make things easier! Unfortunately, there is no magical NewMail collection. You have to build it, and hook into it at the proper time. What is essential is instantiating the necessary objects when Outlook starts. To begin, open the Visual Basic Editor (ALT+F11) and open the ThisOutlookSession module from the Project Explorer window. The first code that we need to add are module level variables that we'll declare in the general declarations section of the module at the top:

Option Explicit
Private objNS As Outlook.NameSpace
Private WithEvents objNewMailItems As Outlook.Items

The most important object in this example is objNewMailItems, as we'll soon see. The "WithEvents" statement means we are declaring this object in a way that will allow us to access not only the properties of that object, but also the events that the object exposes.

Now, we have to hook these variables up. The ThisOutlookSession module is special compared to the regular modules that you usually insert into a VBA project in Outlook - it has a "built-in" Application object variable already declared. This way you don't have to add a "Private WithEvents objApp As Outlook.Application" line or something similar in the general declarations section of the module. With that in mind, add this procedure:

Private Sub Application_Startup()

Dim objMyInbox As Outlook.MAPIFolder

Set objNS = Application.GetNamespace("MAPI")
Set objMyInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objNewMailItems = objMyInbox.Items
Set objMyInbox = Nothing
End Sub

This is essentially where it all begins. As the name of the Application_Startup event indicates, this loads when Outlook launches and is essential to ensure that we gain access to e-mails delivered to the Inbox. This is done by hooking up an event aware procedure tied to the Items collection that we retrieve from the MAPIFolder object we set from the Inbox folder. The event where all the processing on incoming e-mails occurs will be here:

Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)

Dim objEmail As Outlook.MailItem
'Ensure we are only working with e-mail items
If Item.Class <> OlItemType.olMailItem Then Exit Sub

Debug.Print "Message subject: " & objEmail.Subject
Debug.Print "Message sender: " & objEmail.SenderName & " (" & objEmail.SenderEmailAddress & ")"
Set objEmail = Nothing
End Sub

And that's really all there is to it! The Item object is checked to ensure that it is a MailItem object before we work with it any further.
Once it is validated, we can work with all the properties and methods of the MailItem object to do whatever we want with it. Just printing out the subject line and sender information to the Debug window like the example above is pretty boring, but there are all kinds of possibilities using code to work with e-mails in ways that the Rules Wizard can't handle:

- write e-mail info to a database
- automatically save attachments to the file system
- lookup the sender's Contact item and start a Word mail merge using their mailing address
- parse the message body for line items to be added to a spreadsheet

Those are just a few examples, but as long as whatever you want to do has an Object Model it can be done - you don't just have to automate Outlook or other Office applications.

There are a few caveats to mention though. If a large number of items are added to a folder at that same time, the ItemAdd event may not fire.
This is documented in this KB article:

OL2002: ItemAdd Event Doesn't Run in Some Scenarios:
http://support.microsoft.com/?kbid=290653

However, you can get around this if you use Outlook 2003. The NewMailEx event provides a list of all the unique EntryID values for e-mails that were delivered during the last Send/Receive cycle. These values can be used to retrieve each e-mail individually as in the ItemAdd event by using the NameSpace GetItemFromID method.

Private Sub Application_NewMailEx(ByVal EntryIDCollection As
String)
Dim objEmail As Outlook.MailItem
Dim strIDs() As String
Dim intX As Integer
strIDs = Split(EntryIDCollection, ",")
For intX = 0 To UBound(strIDs)
Set objEmail = objNS.GetItemFromID(strIDs(intX))
Debug.Print "Message subject: " & objEmail.Subject
Debug.Print "Message sender: " & objEmail.SenderName & " (" & objEmail.SenderEmailAddress & ")"
Next
Set objEmail = Nothing
End Sub

Note: The Outlook 2003 VBA help file seems to indicate that NewMailEx only works with Exchange Server mailboxes. This is not true - try it and see with POP or IMAP accounts.

Finally, don't expect this code to process e-mails the way server-side based rules do. Outlook of course has to be running for your code rules to work. For requirements where e-mail needs to be processed 24/7, see the Exchange SDK for information on building Event Sinks that run on the server.

To take this example further, there may be situations where you need to interact with e-mails that are opened rather than received. This involves a different approach and is explained in this article:
Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

Is There an Easy Way to Send Screenshots?

Ken asks:

"We are on Exchange Server 2003 & Outlook 2003. We do not enforce standards for email format (RTF, HTML, or Plain Text). Very often people need to send a screen shot to another person within or outside of the company. With today's high resolution screens, these embedded screen shots or attachments can be very large 2-10MB). There are a group of people that use good sense and resize the images or crop them prior to sending, but not everyone is good or capable of doing that.

The other MSFT Office Suite programs like Word and PowerPoint have a very handy one-button tool to compress an image or crop it, this tool (Picture editor) is missing from Outlook unless you are using Word as your email editor (not sure if it's there, but I'm guessing it is).

I'm looking for a way to make this EASY for all of our employees. We have deployed C2C to compress attachments, but it does not resize the image which we would like to do. Things that are automated are better, but if there were an easy way to explain to employees how to do this with existing tools it would be good. Having them copy it into another application first, resize the image, save the file, then paste the document or image is just too much for people to do when they just want to quickly send a screen shot of a problem they are experiencing."

It really depends on how your users are adding the screenshots to the email message. If they paste it into an HTML message body, Outlook won't offer to resize it, but they can use the Picture toolbar to crop or compress it if they use Word as the editor. Cropping or reducing the size is recommended, if only to make the image easier for the recipient to view. Sending the same screenshot in an RTF formatted email results in a much larger message.

If the users save the screenshot as a BMP, JPEG or GIF and insert the image as an attachment, both the Outlook and Word editors offer image resizing via an option in the task pane.

One problem I run into often is that many users only know how to paste a Print Screen into Word and send the document. Along with often resulting in a huge attachment, many people don't like to open Word documents unless they requested them, because of virus concerns. For this reason, pasting screenshots into Word then sending as an attachment should be discouraged.

If this is the only way your users know to do screen prints, they should use Word's Office Envelope feature to send the document as an email.
They can use Word's picture editing option to crop or resize the image before sending but because the image size is reduced by Word to fit the page, they don't have to crop or compress the picture - just paste the picture in the document and add their comments, then click on the Email envelope button on the Standard toolbar or use the File, Send to, Mail recipient menu to display the email address and subject fields.

Keep in mind that in order to send documents in this manner you need to use the same version of Word as Outlook. It won't work if you use Office XP and upgraded Outlook to the newest version. Also, if you use older Office suites your results may vary. Office 2003 does a pretty good job at controlling file size when sending email, even on the default settings. Older Office suites don't clean the resulting messages as well and file sizes will be larger.

A second area where users often go wrong when sending screenshots is sending an image of their entire desktop instead of just the dialog or window they have a question about.

They do this because they don't know that they can copy just the window that is in focus using Alt+PrintScreen. Many users also aren't aware that the text in many dialog boxes can be copied, making it easy to send the exact error message to the recipient without involving screenshots. Click anywhere in the dialog (other than on the Ok or Cancel buttons) and press Ctrl+C to copy it, then paste it into the email. When the dialog supports copying, the paste will look something like this:

---------------------------
Microsoft Office Outlook
---------------------------
Cannot start Microsoft Office Outlook. The command line argument is not valid. Verify the switch you are using.
---------------------------
OK
---------------------------

Many newer applications support copying the text in dialogs so it's worth trying with all dialogs before doing a print screen. If the dialog doesn't copy, use Alt+PrintScreen to avoid typing out the exact error message.

Which Version of Exchange or Outlook Do You Use?

If you haven't responded to the Slipstick polls yet, be sure to visit http://www.slipstick.com/. We want to know the version of Exchange server you're using as well as the version of Outlook and what type of email account is set as your default account in Outlook.

It's not surprising to me that Exchange 2003 holds a wide margin over Exchange 2000 and Exchange 5.5, but Outlook's results did catch me by surprise. I knew from the questions I see about Outlook 2000 usages that it was still used by many sites and home users. While it's far behind Outlook 2003 in our polls, it holds a slight lead over Outlook 2002. Exchange accounts lead POP3 by a respectable margin, but comparing the 55% Exchange use to 45% non-Exchange, our results very much in line with the SQM data Microsoft collects on Outlook usage.

You can respond to the polls and check out the results at http://www.slipstick.com/.

If you're in the mood to answer additional questions, see the complete list of survey questions at http://www.slipstick.com/poll/survey.htm.

"Outlook 2002 Holiday Update" Update

If you tried to download the holiday update I mentioned in the last issue of EMO, you discovered that the download was not available. This is because Microsoft temporarily removed the Outlook 2002 holiday update while they correct the errors in it. Along with the Thailand date mix-ups, Christmas is missing from the US holidays and a few other holidays are either wrong or missing from the file. Once its updated and rechecked it will be available again. Hopefully error-free this time.

http://www.outlook-tips.net/howto/missinghol.htm

Back to Top  

New Utilities

ADDRESSGRABBER BASIC
http://www.egrabber.com/addressgrabberbasic/outlookusers/index.html
AddressGrabber Basic is a FREE tool that helps you to automatically import contact details from any text into Outlook Contacts. This data entry tool can do away with 80% of your data entry time. It enables you to automatically grab Names and addresses from an email, web page or word document into your Outlook in one click.

BACKUP4ALL
http://www.backup4all.com/
Backup4all is backup software for Windows. It was designed to protect your data from partial or total loss by automating tasks, password protecting and compressing it to save storage space. The application offers an intuitive interface making all features accessible for both beginners and professionals. Performs full, incremental, differential & mirror backups. Has wizards for backup & restore, file filters, schedulers, disk spanning, writes to CD/DVD, file version tracking, zip password.

E-MAIL DETECTIVE
http://www.hotpepperinc.com/emdlicense.html
E-Mail Detective is a software tool that extracts all email contents (including graphics) from America Online's database stores on a user's disk drive. Any AOL email that has been cached or saved on a user's disk drive is extracted, complete with all embedded pictures and a comprehensive report is produced that contains all the emails for a user. This report can then be viewed and searched for any specific words or phrases.

EXCHANGE REPORTER
http://www.ssw.com.au/ssw/exchangereporter/
SSW Exchange Reporter provides the tools and reports you need to efficiently analyze your organization's email usage. Exchange Reports range from who is sending the most emails to clients to who has the largest mailbox. The built in reports can be customized and extended because they are built with SQL Server Reporting Services. The SSW Extraction Windows Service runs on your Exchange Server to seamlessly extract your email messages and mail folder statistics. It is a very lightweight Windows Service and the reports are very fast because it uses the power of SQL Server.

EXCHANGEMATIC
http://www.enowconsulting.com/exchangematic/overview.asp
ExchangeMatic saves you time by automating and streamlining your daily exchange tasks. In order to keep your exchange system healthy and happy, the system must be monitored, administered and maintained daily. ExchangeMatic streamlines each of these areas and delivers the complete Exchange Management solution.

EXTREME EMAILS
http://www.ssw.com.au/ssw/eXtremeEmails/
SSW eXtreme Emails enables you to use Microsoft Outlook as a bug tracking and project management system. E-mail is transformed from an unstructured information source into a data-centric tool, permitting reports and data analysis. SSW eXtreme Emails allows you to categorize emails as work tasks (or 'incidents'), and assign properties to permit tracking of those tasks. You can use Exchange Public Folders to share information internally or over the Internet.

FEOX
http://www.feox.com
Feox is an Outlook spam blocker. Use it to choose who and what is allowed into your Inbox. Bounce spam back. Report spammers to the authorities. Forward only good emails to your cell phone. Challenge emails. Convert the Feox toolbar into English, Spanish, French, Italian, and Russian. Fully customizable. Outlook Express version also available.

GNUGP PLUGIN FOR OUTLOOK
http://www3.gdata.de/gpg/download.html
This plugin adds Outlook integration to GnuPG, replacing PGP.

HEXAMAIL GUARD
http://www.hexamail.com/hexamailguard/index.htm
Hexamail Guard ensures SPAM is eliminated at the server level with no need to install and update anti-spam software on each desktop. Hexamail uses a comprehensive set of antispam features including Bayesian analysis that learns from your email traffic. Automatic whitelisting and neural-network based email address analysis eliminate false positives.

HEXAMAIL ROUTER
http://www.hexamail.com/hexamailrouter/index.htm
Hexamail Router acts as a smart rerouter for your incoming and outgoing email. Use sophisticated rules to reroute, block, monitor or perform group distributions.

NK2CSV
http://www.epute.com/nk2csv/
NK2csv is a free utility to view and export the contents of an Outlook autocompletion file. Use it to recover e-mail addresses from a corrupted NK2 file. Currently at version .05 beta.

PERFECTDISK FOR EXCHANGE
http://www.raxco.com/products/pd2kexch/
PerfectDisk for Exchange is an automated compaction/defragmentation solution for Microsoft Exchange data stores. It helps you reclaim valuable disk space for your Exchange servers and maintain optimal Exchange performance by automating the offline compaction/defragmentation process.

PERFECTDISK FOR EXCHANGE
http://www.raxco.com/products/pd2kexch/
PerfectDisk for Exchange automates and schedules the whole ESEUTIL process, reclaiming valuable disk space for your Exchange servers. It helps to maintain optimal Exchange performance by automating the offline compaction/defragmentation process and saves Exchange administrators valuable time, freeing them for other duties. PerfectDisk for Exchange comes with a full license of PerfectDisk Server.

POP3 DOWNLOADER
http://www.hexamail.com/hexamailpop3downloader/index.htm
POP3 Downloader offers real-time POP3 account downloading and forwarding to any email server supporting SMTP. It supports multiple 'fetch all' commands which makes it perfect for gathering email from hosted POP3 mailboxes and pushing to your mailserver. Compatible with Microsoft Exchange server 5.5, 2000 and 2003 and ALL SMTP servers.

RSS2EXCHANGE
http://www.hexamail.com/rss2exchange/index.htm
RSS2Exchange allows you to publish web feeds directly into MS Exchange Public Folders. Supports XML, RSS and Atom Newsfeed technologies.

YPOPS!
http://www.ypopsemail.com/
YPOPs! is an application that provides POP3 access to Yahoo! Mail by emulating a POP3 server and enables POP3 email clients such as Outlook to download email from Yahoo! accounts. It is available for Windows, Linux, Solaris and Mac platforms.

Back to Top  

Updated Utilities

AUTO-MATE FOR OUTLOOK
http://www.pergenex.com/auto-mate/index.shtml
Now available in two versions, Standard and Pro, Auto-Mate is an add-in for Outlook that allows you use define rules to move mail from your Inbox (or other folders) based on several criteria, including the age of the message. The program offers a default set of rules and folders that work in conjunction with Outlook features to organize your mail into folders based on date and To-Do status. Features found in Pro include the ability to assign categories or mark messages with colored flags (Outlook 2003), forward messages to any email addresses or reply to email messages with predefined templates or modify the subject of messages. Additionally, you can export messages to your hard disk in the following formats: Text, MSG, RTF, or HTML or remove attachments and save them to your hard disk or delete them from the message. Inbox Snooze feature allows you to remove messages for a predetermined time, then return them to your Inbox. Supports Outlook 2000, 2002, and 2003.

MAPILAB GROUPWARE SERVER FOR MICROSOFT OUTLOOK
http://www.mapilab.com/groupware/server/
Share any Outlook folders with your team without Exchange Server. MAPILab Groupware Server provides real-time access to special shared folders in the Microsoft Outlook. From a user point of view, folders on MAPILab Groupware Server look and behave exactly the same as folders on Microsoft Exchange Server: the moment someone creates a new note in the folder, you will see it at your place. Version 1.1.0

PROMODAG REPORTS FOR MICROSOFT EXCHANGE
http://www.promodag.com/products/reports/description.aspx
PROMODAG Reports is a reporting tool that analyzes and helps optimize your Exchange messaging system: you can measure the use of your e-messaging system, analyze traffic patterns and establish the cost of using the system. Version 7.2

REMINDER MANAGER
http://www.slovaktech.com/remindermanager.htm
Extended Reminders enables you to get reminders on items in any email, contacts, tasks or calendar folder in your default mail store except the Outbox and Deleted Items folders. New features include a Field Chooser dialog to enable selection of which fields to display and in which order in the reminders window, the ability to group reminders and configure a new Reminder Importance (low, normal, high, critical) field. It supports individual settings per reminder for sending email when the reminder fires. There are new reminder views for next 7 and 30 days and previous 7 and 30 days. It has a fully featured print preview and printing style template dialog where the user can select standard header and footer options for printed reports. It works with Outlook 2000 (corporate or workgroup mode only), Outlook 2002 and Outlook 2003, and with Exchange mailboxes or PST files. Supports Terminal server. Version 2

Back to Top  

New Exchange Knowledge Base Articles

An Exchange Server 2003 virus-scanning program does not obtain sender information from an e-mail message that the program receives from an Exchange Server 5.5 user
http://support.microsoft.com/?kbid=910188

The Exchange System Attendant service starts to quickly increase its memory usage in Exchange 2000 Server
http://support.microsoft.com/?kbid=911289

IMAIL content conversion failures in Exchange Server 2003 may be difficult to isolate
http://support.microsoft.com/?kbid=898601

Vulnerability in TNEF decoding in Microsoft Exchange could allow remote code execution
http://support.microsoft.com/?kbid=894689

MS06-003: Vulnerability in TNEF decoding in Microsoft Outlook and Microsoft Exchange could allow remote code execution
http://support.microsoft.com/?kbid=902412

MS06-003: Vulnerability in TNEF decoding in Microsoft Outlook and Microsoft Exchange could allow remote code execution
http://support.microsoft.com/?kbid=902412

Error message when a DAV client tries to authenticate with an Exchange Server 2003 SP1 front-end server: "HTTP 500 - Internal server error"
http://support.microsoft.com/?kbid=911971

Vulnerability in TNEF decoding in Microsoft Exchange could allow remote code execution
http://support.microsoft.com/?kbid=894689

MS06-003: Vulnerability in TNEF decoding in Microsoft Outlook and Microsoft Exchange could allow remote code execution
http://support.microsoft.com/?kbid=902412

The same date appears two times in the weekly and monthly views of the calendar in Outlook Web Access
http://support.microsoft.com/?kbid=908800

The expected e-mail messages are not found when you use Message Tracking Center in Exchange Server 2003 Service Pack 2
http://support.microsoft.com/?kbid=908977

The offline address book regeneration operation fails, and event ID 9328 may be logged in Exchange Server 2003
http://support.microsoft.com/?kbid=912591

Exchange Server 2003 does not include the "In-reply-to" header field when you use Outlook or Outlook Web Access to reply to an e-mail message that originated from outside the organization
http://support.microsoft.com/?kbid=90802777

You experience poor server performance and difficulty isolating VSAPI-related issues on the Exchange store in Exchange Server 2003
http://support.microsoft.com/?kbid=900403

How to remove the additional domain * in Internet Message Formats in Exchange System Manager
http://support.microsoft.com/?kbid=555552

How to increase the Exchange Server 2003 Service Pack 2 18-gigabyte database size limit
http://support.microsoft.com/?kbid=912375

When you configure the diagnostics logging level to Maximum on the NSPI Proxy service in Exchange Server 2003 Service Pack 1, event ID 9040 is logged in the Application log
http://support.microsoft.com/?kbid=912062

Error message when an application tries to send a message as another user by using Exchange Server 2003: "Access denied"
http://support.microsoft.com/?kbid=912918

Back to Top  

New Outlook Knowledge Base Articles

Description of the Outlook 2003 post-Service Pack 2 hotfix package
(Emsmdb32.dll): December 19, 2005
http://support.microsoft.com/?kbid=912008

Description of the Outlook 2003 post-Service Pack 2 hotfix package for the French version of Outlook 2003: December 21, 2005
http://support.microsoft.com/?kbid=912710

Description of the Outlook 2003 post-Service Pack 2 hotfix package for the Italian version of Outlook 2003: December 21, 2005
http://support.microsoft.com/?kbid=912711

How to use named properties to relate Contact Address Book entries to e-mail messages, e-mail addresses, and picture attachments in Outlook 2003
http://support.microsoft.com/?kbid=912237

How to use MAPI to manage messages in a .pst file when you are using Outlook 2003 to download messages from an IMAP server
http://support.microsoft.com/?kbid=912238

Description of the Outlook 2003 post-Service Pack 2 hotfix package for the German version of Outlook 2003: December 16, 2005
http://support.microsoft.com/?kbid=910833

Description of the Outlook 2003 post-Service Pack 2 hotfix package: December 15, 2005
http://support.microsoft.com/?kbid=912444

Error message in an NDR when you send an e-mail message in Outlook: "Error: ' 553 sorry, that domain isn't in my list of allowed RPC hosts.'"
http://support.microsoft.com/?kbid=912163

An Office 2003 program unexpectedly quits with an unrecoverable error when the program is started by another program that is running under a non-interactive account
http://support.microsoft.com/?kbid=912448

Description of the Office 2003 post-Service Pack 2 hotfix package:
December 16, 2005
http://support.microsoft.com/?kbid=912022

Description of the Office 2003 post-Service Pack 2 hotfix package for the German version of Outlook 2003: November 17, 2005
http://support.microsoft.com/?kbid=909111

Description of the Office 2003 post-Service Pack 2 hotfix package for the German version of Outlook 2003: December 16, 2005
http://support.microsoft.com/?kbid=910833

Description of the Office 2003 post-Service Pack 2 hotfix package for the German version of Outlook 2003: December 21, 2005
http://support.microsoft.com/?kbid=912443

Description of the Office 2003 post-Service Pack 2 hotfix package:
December 15, 2005
http://support.microsoft.com/?kbid=912004

Description of the Outlook 2003 post-Service Pack 2 hotfix package
(Dlgsetp.dll): December 19, 2005
http://support.microsoft.com/?kbid=912007

Description of the security update for Outlook 2003: January 10, 2006
http://support.microsoft.com/?kbid=892843

Description of the Office 2003 post-Service Pack 2 hotfix package:
December 6, 2005
http://support.microsoft.com/?kbid=911888

How to use the dispidHeaderItem MAPI property to identify the state of a message that you receive in Outlook 2003
http://support.microsoft.com/?kbid=912239

Description of the Dutch Multilingual User Interface Pack for Office 2003 post-Service Pack 2 hotfix package: December 15, 2005
http://support.microsoft.com/?kbid=910288

How to migrate your Lotus Notes contacts to Outlook 2003
http://support.microsoft.com/?kbid=912804

Error message when you try to print another user's shared calendar in Outlook 2003: "The messaging interface has returned an unknown error"
http://support.microsoft.com/?kbid=912803

Back to Top  

More Information

ISSN 1523-7990
Copyright 1996-2006, Slipstick Systems and CDOLive LLC. All rights reserved.