Skip to main content

Public folder Mail Re-Submit Tool

I came up with this little application this week to solve one annoying problem I have with a small client that uses an anti-spam application that submits any SPAM it finds to a public folder. As with everything the cheaper the anti-spam software the more chance there will be false positives so occasionally there is a need to go though this public folder and forward any false positives on to the intended receiver. Using the normal Outlook or OWA method will change the reply address’s and also the subject line which is usually also altered by the anti spam program. So what I came up with was two simple ASP pages that could be used to firstly query all the mail in a public folder and then allow an export (which is sometimes useful for checking the X-headers added by this spam program) and also resubmit an email to a desired email address (and allow any fix-up to the subject) buy firstly getting the RFC822 stream of the message via CDOEX and then saving this stream with an added x:sender and x:receiver field to the pickup directory on the server.

The Resubmit Trick

I picked up this resubmit trick by basically copying what the IMF and IMF archive managers do. If you have UCE Archiving enabled with IMF it saves a copy of any SPAM it detects to a directory and writes the sender and reciver address’s as x:sender and x:receiver at the top of the file. If these two fields are at the top of the file when you put a mail into the pickup directory Exchange will process these as the envelope fields and only attempt to deliver the message to the x:receiver address (and not the To and CC fields of the message). I started out thinking I could do this by adding the X-header’s via the fields collection in CDOEX like I usually do which works but created a problem that because using the procedure for some reason added another field to the top of the file before x:sender and x:receiver when exchange processed the email that was placed in the pickup directory it would also try and resend the email to any of the address’s that where in the To and CC field of the message (which is a really bad thing).To fix this problem I ended up getting the stream of the message appending to the front of the steam and then writing it to disk which made sure that these two fields where always at the top of the file

Using the tool

The two asp pages that make up this tool use Exoledb as the underlying mechanism to access the Exchange Store. This means that the pages must be run locally on an Exchange server that has an instance of the public folder you want to access. To run the tool it needs to be put into a directory usually under the default website (eg create a directory under wwwroot called resub) that has NTLM authentication enabled (via IIS admin). Because this was a really simple tool I’ve also hard coded the Pickup directory in the ASP file so if you have the pick directory set to any other directory other then “c:\Program Files\Exchsrvr\Mailroot\vsi 1\PickUp” you need to change the following line in expresub.asp file

dim rec,oCon,Href,msgobj,resub,Subject,Toaddress,pickupdirectory,rfcmsg
pickupdirectory = "c:\Program Files\Exchsrvr\Mailroot\vsi 1\PickUp"

This tool is not just limited to public folders if you have a mailbox you want to re-submit messages from it will also work just enter in the OWA url to the inbox you want (eg: http://servername/exchange/username/inbox ) and press submit. The main page of this application is called resubmain.asp so if you have placed the files in a directory called resub under wwwroot you should be able to access the tool by using http://servername/resub/resubmain.asp .

Limitations

One limitation is that you can only submit a message to one email address and you should only resubmit messages to internal address resubmitting to external address may cause unexpected results.

Changing Export format

Currently the export format is set to .txt files this is mainly because I wanted to be able to view the message in notepad. If you wanted to export the message as a .eml just change the extension in the following line in resubmail.asp and you will then be able to open the message in Mail client such as Outlook Express

Response.AddHeader "Content-Disposition","attachment;filename=export.txt"

Change to

Response.AddHeader "Content-Disposition","attachment;filename=export.eml"

Download

I’ve put a download of the ASP pages here

Popular posts from this blog

Testing and Sending email via SMTP using Opportunistic TLS and oAuth in Office365 with PowerShell

As well as EWS and Remote PowerShell (RPS) other mail protocols POP3, IMAP and SMTP have had OAuth authentication enabled in Exchange Online (Official announcement here ). A while ago I created  this script that used Opportunistic TLS to perform a Telnet style test against a SMTP server using SMTP AUTH. Now that oAuth authentication has been enabled in office365 I've updated this script to be able to use oAuth instead of SMTP Auth to test against Office365. I've also included a function to actually send a Message. Token Acquisition  To Send a Mail using oAuth you first need to get an Access token from Azure AD there are plenty of ways of doing this in PowerShell. You could use a library like MSAL or ADAL (just google your favoured method) or use a library less approach which I've included with this script . Whatever way you do this you need to make sure that your application registration  https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-

How to test SMTP using Opportunistic TLS with Powershell and grab the public certificate a SMTP server is using

Most email services these day employ Opportunistic TLS when trying to send Messages which means that wherever possible the Messages will be encrypted rather then the plain text legacy of SMTP.  This method was defined in RFC 3207 "SMTP Service Extension for Secure SMTP over Transport Layer Security" and  there's a quite a good explanation of Opportunistic TLS on Wikipedia  https://en.wikipedia.org/wiki/Opportunistic_TLS .  This is used for both Server to Server (eg MTA to MTA) and Client to server (Eg a Message client like Outlook which acts as a MSA) the later being generally Authenticated. Basically it allows you to have a normal plain text SMTP conversation that is then upgraded to TLS using the STARTTLS verb. Not all servers will support this verb so if its not supported then a message is just sent as Plain text. TLS relies on PKI certificates and the administrative issue s that come around certificate management like expired certificates which is why I wrote th

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Graph is limited to a m
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.