Queens Dev
Some more ASP.NET

System.Net.Mail - Command Not Implemented

September 19, 2008 at 5:20 AM by bjsetegn

While setting up the e-mailing features int log4net for an ASP.NET 2.0 project I kept receiving the following exception:

System.Net.Mail.SmtpException: Command not implemented. 
 The server response was: Command not implemented
   at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at log4net.Appender.SmtpAppender.SendEmail(String messageBody)
   at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[] events)

I found this troubling because I had used this feature before and had no problem sending e-mails from other applications.  Also another developer was able to use the same exact log4net code on their machine and it worked.  It turned out that the host I was using wasn't setup for relaying e-mails through their e-mail server.  When I used the .NET 1.1 System.Web.Mail classes with the same e-mail server and configuration I would not receive the exception.  It uses a slightly different communication protocol (HELO vs EHLO) that doesn't require relaying to be setup on the e-mail server. So if all else fails and you get the Command Not Implemented exception you could always use the .NET 1.1 System.Web.Mail class.

More Info

http://msexchangeteam.com/archive/2004/02/19/76432.aspx - For setting up an email server for relaying.

http://code.msdn.microsoft.com/KB913616 - For a possible hotfix.

Convert Code Syntax Highlighting to HTML for Posting Online

September 18, 2008 at 5:11 AM by bjsetegn

I come across many websites and blogs these days that still don't format their code well when posting it online.  Whenever I see a site with poorly styled code I wonder how good of a programmer they actually are and how little effort they put into their site.  For those of us with Visual Studio this task has been made pretty simple thanks to a tool called CopySourceAsHtml.  This simple tool integrates with Visual Studio to allow you to copy out its syntax highlighting to html exactly as you see it.  Since Visual Studio adds syntax highlighting to many common file types it makes its easy to generate html from almost any of your source code.

I found this tool to be the easiest to use because it doesn't require you to install or change anything on your website.  It also creates html that displays well in most browsers.  Some browsers like Internet Explorer will ignore tags like <pre> which is used to mark text as preformatted.  CopySourceAsHtml doesn't use <pre> tags it mostly uses <p> paragraphs and <span> spans.  It also lets you add specific styling to certain sections making it more dynamic.  A link to the author's website for more details and a download are below.  Also included is a link to convert the add-on to run in Visual Studio 2008.

Links

http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/- Copy Source As HTML

http://developers.de/blogs/andreas_erben/archive/2007/08/01/using-copysourceashtml-with-visual-studio-2008-beta-2.aspx- Visual Studio 2008 Fix