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

cdemott33Asked:
Who is Participating?
 
Luis PérezSoftware Architect in .NetCommented:
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.
0
 
cdemott33Author Commented:
Thank you.  Using the Fulling qualified reference worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.