Introduction

This article describes SMTP Transport Events in the Microsoft SMTP server. The article shows how to write simple scripts and how to install these scripts.
The article also shows how to write incoming emails to a database and how to mark incoming emails with a red follow up flag.

Background

Recently I was asked to work out a way to get Exchange 2000 to mark some
incoming emails with a red follow up flag. I started looking through MSDN and I
came across SMTP Server Events.
I discovered that there are 2 types of events:

Protocol Events

Transport Events

This article is going to discuss transport events.

Transport events occur when an email has been received by the SMTP server. The event that I want to discuss is the OnSubmission event, there are 2 other events: OnPreCategorize and OnPostCategorize.
The OnTransportSubmission event is the same event as the CDO for Windows 2000 OnArrival event.
The OnTransportSubmission event is called with the following prototype:

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)

A CDO MailMsg object is passed into the sub routine, with this we have full access to the email that the server is processing.
So the full code to add a red follow up flag would be:

This just sets the property on the BouncedEmail event, telling it where to locate the script.

Un-installation is a simple process:

cscript smtpreg.vbs /remove 1 onarrival BouncedEmail

Points of Interest

I came across an interesting problem whilst implementing the red follow-up flag. The client wanted incoming emails to be marked with the follow up as well as internal emails going to a certain address.
At first this wasn't working for internal addresses, this is because Outlook uses MAPI to communicate with exchange rather than SMTP.
Microsoft issued this KB Article explaining the problem. The work around is pretty messy, it involves adding a new virtual SMTP server and bouncing
emails off it, this makes the event fire because it goes from outlook to exchange as MAPI then from exchange to the virtual SMTP server back to exchange again.

I hope this simple article can provoke some thought. I might mention that you can write your own COM add-ins that perform the same functions, of course these would give better performance. I wouldn't like to run these VB scripts on a server that has a very high demand, you might notice some performance problems.
The projects I've used these techniques on have suffered no such problems however.

History

20/12/2002 - Article Created

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.