Hello,
I am getting an error in the final Email Try It Out. When loading the page I get the following error. The problem is in the "Message.Visible = True" line, but I can't figure out how to fix it.
"Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30389: 'System.Net.Mail.Message' is not accessible in this context because it is 'Friend'.
Source Error:
Line 35: mySmtpClient.Send(myMessage)
Line 36:
Line 37: Message.Visible = True
Line 38: FormTable.Visible = False
Line 39: End If
Source File: C:\BegASPNET\Site\Controls\ContactForm.ascx.
vb Line: 37"
Below is all the code in the ContactForm.ascx.
vb:
Code:
Imports System.IO ' Provides access to the File class for reading the file
Imports System.Net.Mail ' Provides access to the various mail related classes
Partial Class Controls_ContactForm
Inherits System.Web.UI.UserControl
Protected Sub CustomValidator1_ServerValidate(source As Object, args As ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If Not String.IsNullOrEmpty(PhoneHome.Text) OrElse Not String.IsNullOrEmpty(PhoneBusiness.Text) Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
Protected Sub SendButton_Click(sender As Object, e As EventArgs) Handles SendButton.Click
If Page.IsValid Then
Dim fileName As String = Server.MapPath("~/App_Data/ContactForm.txt")
Dim mailBody As String = File.ReadAllText(fileName)
mailBody = mailBody.Replace("##Name##", Name.Text)
mailBody = mailBody.Replace("##Email##", EmailAddress.Text)
mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text)
mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text)
mailBody = mailBody.Replace("##Comments##", Comments.Text)
Dim myMessage As MailMessage = New MailMessage()
myMessage.Subject = "Response from web site"
myMessage.Body = mailBody
myMessage.From = New MailAddress("[email protected]", "Sender Name")
myMessage.To.Add(New MailAddress("[email protected]", "Receiver Name"))
myMessage.ReplyToList.Add(New MailAddress(EmailAddress.Text))
Dim mySmtpClient As SmtpClient = New SmtpClient()
mySmtpClient.Send(myMessage)
Message.Visible = True
FormTable.Visible = False
End If
End Sub
End Class