Posts Tagged ‘badmail’

Processing e-mail from unresolved (external) senders

February 23, 2011 2 comments

You probably already know that Service Manager will discard e-mail from senders it does not recognize, into the BadMail folder.  If you are not monitoring this folder, you could miss incident requests from users who occasionally, for one reason or another, send e-mail from their personal/home e-mail address rather than their corporate Active Directory linked e-mail address.  The solution described here is one I developed and implemented with a client in December 2010.  It eliminates the need to monitor the BadMail folder, and automatically creates incidents of all e-mails discarded by Service Manager.

The External Mail Processor Service

The External Mail Processor Service is a Windows service that can run on any computer with the .Net framework 3.5 or higher.  The only security requirements are that the service account have access to Service Manager’s BadMail folder, and be able to create incidents in Service Manager.

The External Mail Processor service works by monitoring the BadMail folder with a file system watcher.  When Service Manager discards an incident e-mail file (.eml) into the BadMail folder, the service detects and immediately processes the file.  An incident is created of the e-mail just as Service Manager would.  The e-mail subject becomes the incident title, the first 4000 characters of  the body body become the incident description, and the .eml file itself is added as an attachment to the incident.  One notable difference is that the senders e-mail address is added as the Alternate Contact Method of the incident, rather than as the Affected User.  The service also enables ignoring e-mails based on senders address or subject.

Configuring and Installing the Service

Download and extract the file to a computer running the .Net framework 3.5.  The zip file includes the following files:

  • SMExtMailProcessor.exe
  • SMExtMailProcessor.exe.config
  • Microsoft.EnterpriseManagement.ServiceManager.dll
  • Microsoft.EnterpriseManagement.Packaging.dll
  • Interop.CDO.dll
  • Interop.ADODB.dll

Using a text or XML editor, open SMExtMailProcessor.exe.config to customize the settings.  There are two kinds or settings.  Single value settings such as

            <setting name="BadMailFolder" serializeAs="String">

which take a single value and multi-value settings such as

            <setting name="IgnoreSenders" serializeAs="Xml">
                    <ArrayOfString xmlns:xsi=""

which can have multiple values each surrounded by a <string></string> tag.

The settings to be customized are:

  • BadMailFolder: Single value. The location of Service Manager’s BadMail folder.  This can be a local path or a UNC.  Verify that the service account has the necessary NTFS and/or share permissions.
  • ProcessedFolder: Single value. You need to create this folder.  All processed .eml files will be placed into this folder *if* the DeleteAfterProcessing setting is set to False.
  • IgnoreSenders: Multiple values.  List of e-mail address to ignore (not create incidents).  A ‘contains’ comparison of these values to the senders e-mail address is performed, so you can specify partial strings here – such as just the domain name if you want to ignore an entire domain.
  • IgnoreSubjects: Multiple values.  List of e-mail subjects to ignore.  This is also a ‘contains’ comparison.
  • IncidentIDPrefix: Single value.  A prefix for incidents created.  This is typically IR.
  • IncidentSubjectPrefix: Single value.  Optional.  A string to prefix the Title of each incident.
  • DeleteAfterProcessing: Single value. Set this value to True if you want the .eml files deleted after they are processed.  If you set it to False, the files will be moved to the ProcessedFolder after processing.
  • ManagementServer: Single value.  The Service Manager management server.  If you run this service on the Service Manager server, leave this value as localhost.
  • Verbose: Single value.  Set to False unless when troubleshooting.

After modifying the .config file, you need to install the service. The service needs to run with a domain account.  The account must have permissions to read, write and delete in the BadMailFolder and ProcessedFolder folders specified in the .config file, and must have permissions in Service Manager to create incidents. 

To install the service, open an elevated command prompt at the folder with the extracted files and run:

\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe SMExtMailProcessor.exe

The assembly installer will prompt you to specify a service login and password.  The installation is logged to InstallUtil.InstallLog in the same folder, which can be opened with notepad.  After successful installation, you can start the service using Services.msc.  The service name is “Service Manager External Mail Processor”. 

The service logs to the Windows application event log, event source ‘SMExtMailProcessor’.

Uninstalling the Service

Open an elevated command prompt at the folder with the service executable and run:

\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe /u SMExtMailProcessor.exe