Archive

Archive for February, 2011

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 SMExtMailProcessor.zip 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">
                <value>C:\inetpub\mailroot\BadMail</value>
            </setting>

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

            <setting name="IgnoreSenders" serializeAs="Xml">
                <value>
                    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                        <string>JoeSpammer@spammail.com</string>
                        <string>Sue@buycheapdrugs.com</string>
                    </ArrayOfString>
                </value>
            </setting>

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

Advertisements

Service Manager E-mail pre-processor Service

February 14, 2011 4 comments

In early November 2010, a good two months before the Service Manager Exchange Connector was released, I needed to provide an incident e-mail handling solution for a client.  I looked at and was inspired by Anders Bengstsson solution but wanted something more robust, so I decided to write a Windows service that uses file system watchers and multiple worker threads.

So why post this now after the Service Manager Exchange connector has been released?  Well, because someone out there might find it useful – someone who maybe doesn’t use Exchange (gasp 🙂 )or uses a version of exchange prior to Exchange 2007, or maybe even just wants a quite simple solution.

The Service Manager E-mail Pre-processor service works by intercepting SMTP mail before it gets to Service Manager.  The .eml files are properly parsed using Collaborative Data Objects (CDO) for Windows and the subject line is further parsed for incident tokens.  If incident tokens are present, the incident ID is parsed and used to update the incident.  The first 4000 characters of the email body are added as a comment to the incident, and the eml file is added as an attachment.  If incident tokens are not present, the e-mail is moved into another folder from which Service Manager reads.

Configuring and Installing the Service

The Service Manager E-mail pre-processor service can be installed and run from any Windows computer running The .Net 3.5 framework.

Download the SMEmailPreProcessor.zip file, which contains the following files

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

Extract all files into the same folder.  Using a text or XML editor, open SMEmailPreProcessor.exe.config and edit the settings under the <SMEmailPreprocessor.Properties.Settings> node.  Each setting name is shown as

<setting name=”Setting_NameserializeAs=”string”> and the settings value is within the <value> </value> tags.



The settings are:

  • DropFolder”: This is the SMTP drop folder for the Service Manager SMTP domain.  This like other settings folders can be a local or UNC path
  • NewIncidentFolder”: This is a new folder you need to create.  After parsing each .eml file, if the service determines that the e-mail is not an incident reply e-mail, the .eml file is moved into this folder to be picked up by Service Manager.  Note that you must edit Incident Incoming E-Mail settings in Service Manager to specify this folder as the SMTP Drop folder, rather than the default drop folder above.
  • IncidentTokenStart“: This token denotes the start of the incident ID in the e-mail subject line.  Any characters after this start token and before the end token (below) will be read as the incident ID.  The start token can be one or more characters.  Be sure to use unique characters that would typically not be used in an e-mail subject.
  • IncidentTokenEnd“:  This token denotes the end of the incident ID in the e-mail subject line.  If you use the sample start token of [# and the sample end token of ] , the incident ID in the subject line would be something like [#IR3612] where the incident ID is IR3612.
  • IncidentComment“:  You generally want to leave the value for this setting blank.  Any value you specify here will be used instead of the e-mail body as the incident comment.
  • BadMailFolder“:  Where to place .eml files that could not be processed.
  • ManagementServer“:  The Service Manager management server name.  If the service runs locally on the management server, leave the value as localhost.
  • Verbose“:  Leave this value set to False.  Make it True only if you are troubleshooting a problem.

 

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 to the SMTP folders specified in the .config file, and must have Incident Resolver permissions in Service Manager.  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 SMEmailPreProcessor.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.  The file can be opened with notepad.  After successful installation, you can start the service using Services.msc.  The service name is “SM Email Preprocessor”. 

Remember that before starting the service, you must change the Service Manager Incident Incoming E-Mail settings to the value specified as the “NewIncidentFoder”.

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

 

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 SMEmailPreProcessor.exe

You’d then want to restore the Service Manager Incident Incoming E-Mail settings to the default SMTP drop folder.

Categories: Service Manager