John
John

Reputation: 681

Type MailMessage is not defined

Trying to get a simple mail script up and running in .NET. The problem is that I keep getting the error message Type MailMessage is not defined, but I have imported System.Net.Mail in the CodeFile. Below is my Default.aspx.vb.

If I declare it like <%@ Import Namespace="System.Web.Mail"%> at the top of the file and don't use a MasterPage and CodeFile it works, but then I can't use MasterPage.

I'm new at this. What am I missing?

Imports System.Data
Imports System.Xml
Imports System
Imports System.Web
Imports System.Net.Mail

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Me.IsPostBack = False Then

    End If
End Sub

End Class

Beginning of my mail script looks like this:

<script runat="server">
    Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)   


    Dim myMail As New MailMessage()

Upvotes: 0

Views: 1946

Answers (1)

Satpal
Satpal

Reputation: 133423

Assuming you are writing your code in aspx page

Add Import statement after page directive

<%@ Import Namespace="System.Web.Mail"%>

Or

Dim myMail As New System.Net.Mail.MailMessage()

Upvotes: 2

Related Questions