Link to home
Start Free TrialLog in
Avatar of cdemott33
cdemott33Flag for United States of America

asked on

Importing System.Net.Mail within Global.asax

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.To.Add("me@email.com")
        message.From = New MailAddress("info@email.com", "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

        smtp.Send(message)
    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
       
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cdemott33

ASKER

Thank you.  Using the Fulling qualified reference worked.