Tuesday, April 18, 2006

I have finally got around to releasing a cool assembly (dll) that will send SMTP mail for you. It's written in .NET 1.1 and either uses a given SMTP server or the current servers SMTP service (default), if it's installed. The cool thing is that if you are using the server SMTP service and it's not started, then this assembly will try to start it for you.

We are currently using this assembly where I work to send email from ASP.NET and SQL Server.

Code Examples

Here is an example of using the assembly to send mail with the current server SMTP service:

Dim objTest As New VSDNTips.Mail.WebMail()
objTest.Send("#ITDevelopers@mycompany.com", "leaddeveloper@mycompany.com", _
  "Work Project Tomorrow", "Work Proceeds tomorrow as planned.", _
   VSDNTips.Mail.WebMail.MailFormat.HTML)

Here is an example of using an external SMTP server:

Dim objTest As New VSDNTips.Mail.WebMail("mail.mycompany.com")
objTest.Send("#ITDevelopers@mycompany.com", "leaddeveloper@mycompany.com", _
  "Work Project Tomorrow", "Work Proceeds tomorrow as planned.", _
   VSDNTips.Mail.WebMail.MailFormat.HTML)

Here is a real world example that sends email based on an unhandled exception in ASP.NET:

 Private Sub Global_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
    Dim serverError As Exception = Server.GetLastError().GetBaseException()
    Dim errorMessage As New System.Text.StringBuilder("Error Caught in Global_Error event:" & vbCrLf)
    errorMessage.AppendFormat("Error in: {0}{1}", Request.Url.ToString(), vbCrLf)
    errorMessage.AppendFormat("Error Message: {0}{1}", serverError.Message.ToString(), vbCrLf)
    errorMessage.AppendFormat("Stack Trace: {0}{1}", serverError.StackTrace.ToString(), vbCrLf)
    Try
      Dim mailServer As New VSDNTips.Mail.WebMail("mail.mycompany.com")
      mailServer.Send("#ITDevelopers@mycompany.com", "leaddeveloper@mycompany.com", _
String.Format("Error in {0} v{1}", System.Reflection.Assembly.GetExecutingAssembly.GetName.Name, _
System.Reflection.Assembly.GetExecutingAssembly.GetName.Version().ToString()), _
errorMessage.ToString, VSDNTips.Mail.WebMail.MailFormat.Text)
    Catch
    End Try
    Response.Write("<h3>There has been an error in this program. The MyCompany IT staff has been 
                     alerted. Please try again later.</h3>")
    Server.ClearError()
  End Sub

To download, click on the link below:

VSDNTIPS.Mail.zip (2.67 KB)

Tuesday, April 18, 2006 7:16:32 PM (Pacific Daylight Time (Mexico), UTC-07:00)  #    Comments [0]  | 
Monday, April 17, 2006

There is going to be a Code Camp in the Phoenix area on May 6th. I will be presenting two talks:

  • .NET Coding Standard & Best Practices
  • Unlock the Power of WMI

If you live in that area, you should come check out these talks and the others being offered. Hey, it's free! Click on the link below for more info:

http://desertcodecamp.com/

Monday, April 17, 2006 7:02:29 PM (Pacific Daylight Time (Mexico), UTC-07:00)  #    Comments [0]  | 
Tuesday, April 11, 2006

On April 13th I will be doing a talk based on my book (VSDN Tips & Tricks .NET Coding Standards) at the beginners sig of the San Diego .NET Users Group. For location and more info, please click on the link below:

http://www.sandiegodotnet.com/SDNETUG/DesktopDefault.aspx?tabid=24

Tuesday, April 11, 2006 7:26:35 PM (Pacific Daylight Time (Mexico), UTC-07:00)  #    Comments [0]  | 
Monday, April 03, 2006

On April 3, Microsoft announced that Virtual Server 2005 R2 Enterprise Edition will become available as a free download. You can use Virtual Server to create a robust virtualization environment for your production server consolidation, to support disaster recovery and high availability scenarios, and to consolidate mixed workloads including Linux guest operating systems.

Monday, April 03, 2006 7:17:05 PM (Pacific Daylight Time (Mexico), UTC-07:00)  #    Comments [1]  | 

Theme design by Jelle Druyts