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

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 Gr...

Exporting and Uploading Mailbox Items using Exchange Web Services using the new ExportItems and UploadItems operations in Exchange 2010 SP1

Two new EWS Operations ExportItems and UploadItems where introduced in Exchange 2010 SP1 that allowed you to do a number of useful things that where previously not possible using Exchange Web Services. Any object that Exchange stores is basically a collection of properties for example a message object is a collection of Message properties, Recipient properties and Attachment properties with a few meta properties that describe the underlying storage thrown in. Normally when using EWS you can access these properties in a number of a ways eg one example is using the strongly type objects such as emailmessage that presents the underlying properties in an intuitive way that's easy to use. Another way is using Extended Properties to access the underlying properties directly. However previously in EWS there was no method to access every property of a message hence there is no way to export or import an item and maintain full fidelity of every property on that item (you could export the...

Sending a Message in Exchange Online via REST from an Arduino MKR1000

This is part 2 of my MKR1000 article, in this previous post  I looked at sending a Message via EWS using Basic Authentication.  In this Post I'll look at using the new Outlook REST API  which requires using OAuth authentication to get an Access Token. The prerequisites for this sketch are the same as in the other post with the addition of the ArduinoJson library  https://github.com/bblanchon/ArduinoJson  which is used to parse the Authentication Results to extract the Access Token. Also the SSL certificates for the login.windows.net  and outlook.office365.com need to be uploaded to the devices using the wifi101 Firmware updater. To use Token Authentication you need to register an Application in Azure https://msdn.microsoft.com/en-us/office/office365/howto/add-common-consent-manually  with the Mail.Send permission. The application should be a Native Client app that use the Out of Band Callback urn:ietf:wg:oauth:2.0:oob. You ...
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.