View Full Version : Sending a simple mail in ASP.NET

03-08-2007, 12:11 PM
Hello everyone,

Would anyone disagree that the following code for sending an email from a web site contact page is correct (classic three text box scenario; sender's email address, subject and message body):

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Build a MailMessage
Dim mailMessage As System.Net.Mail.MailMessage = New_ System.Net.Mail.MailMessage
mailMessage.From = txtEmail.txt
mailMessage.To = "enquiries@mywebsite.com"
mailMessage.Subject = txtSubject.tex

mailMessage.Body = txtMessage.Text

Dim smtp As New SmtpClient("smpt.fasthosts.co.uk")

Label1.Text = "Your Mail was sent."
Catch exp As Exception
Label1.Text = "There was and error Sending the mail: " & exp.Message
End Try
End Sub

Many thanks in advance

03-15-2007, 05:31 PM
What error are you getting?

I would remove the underscore after 'New'.

03-15-2007, 06:04 PM
Thanks for the reply Erica. I managed to get it functioning not too long after the post. Have another problem though (a seemingly huge one), but will post it under the appropriate heading.