9/07/2007

The specified string is not in the form required for a subject

At one of my "Playground" sites, BlogMetaFinder.com, I get an approval email every time somebody submits a blog or website to the directory. ( If you have any kind of  blog or website related to blogging I encourage you to submit it there).  All submissions go into the database, but they are marked as "Active=0" until such time as i review the submission via a link to a special "Admin" page that I get in the email. It only takes me a second to inspect a site that represents a  legitimate submission (e.g., not porn, not drugs, no redirects, no funny business script kiddie bullshit, etc.) and put the form into edit mode, mark the "Active" checkbox, and update the record which makes it activated into the directory immediately.

However, you always get the occasional bot or bullshit artist that wants to try and see if they can pull a fast one, and they submit junk in the hopes that my directory isn't smart enough to stop them. Invariably, the subject line of the email I get, which includes their submitted site title, has B.S. in it. The result may be that the System.Net.Mail namespace throws an exception, and usually the culprit is the subject line as mentioned in the title of this post.

Here is an easy fix:

subject= Regex.Replace(subject, @"[^ -~]", "");