Importing System.Net.Mail within Global.asax

Posted on 2011-10-31
Medium Priority
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@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

    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

Luis Pérez earned 2000 total points
ID: 37057816
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

ID: 37057928
Thank you.  Using the Fulling qualified reference worked.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

840 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