Importing System.Net.Mail within Global.asax

Posted on 2011-10-31
Last Modified: 2012-05-12
This is my first time working with a Global.asax file.  I'm trying to send an email if an application error occurs, but I can not seam to figure out how to Import System.Net.Mail in order to get it running.  Can someone tell me what I need to do.  Thanks
<%@ Application Language="VB" %>

<script runat="server">
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
    End Sub
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application shutdown
    End Sub
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
        Dim message As New MailMessage()

        message.From = New MailAddress("", "info")
        message.Subject = "Critical Application Exception: " & Request.Path
        message.IsBodyHtml = True

        message.Body = "<html><body><h1>" & Request.Path & "</h1>" &  
                         Server.GetLastError.ToString() & "</body></html>"

        Dim smtp As New SmtpClient

        smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis

    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a new session is started
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a session ends. 
        ' Note: The Session_End event is raised only when the sessionstate mode
        ' is set to InProc in the Web.config file. If session mode is set to StateServer 
        ' or SQLServer, the event is not raised.
    End Sub

Open in new window

Question by:cdemott33
    LVL 25

    Accepted Solution

    What's the problem? You can use System.Net.Mail within global.asax. If you can't use Imports System.Net.Mail, then simply add full-qualified references to your objects:

    Dim message As New System.Net.Mail.MailMessage()
    ... and so on.

    Hope that helps.

    Author Closing Comment

    Thank you.  Using the Fulling qualified reference worked.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now