Try this code (I've taken some bits out of my code, which is why SQLClient is in there, it retrieves the email from the users record)
Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Mail
Partial Class ContactUs
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' ---------------------------------------------------------------------------
' Send an email
' ---------------------------------------------------------------------------
Dim Email As String
Dim sBody As String
Dim Msg As Net.Mail.MailMessage = New Net.Mail.MailMessage()
Dim MailObj As New Net.Mail.SmtpClient()
sBody = "The following message was sent from the Contact Us page"
Email = "
[email protected]"
Msg.From = New Net.Mail.MailAddress("
[email protected]", "Your Friendly Name")
Msg.To.Add(New Net.Mail.MailAddress(Email))
Msg.IsBodyHtml = "True"
Msg.Body = sBody
Msg.Subject = "Contact Us Message"
Try
MailObj.Send(Msg)
Catch ex As Exception
Response.Write(ex.Message) 'Write error message
Exit Sub
End Try
MsgBox("Thank you for sending your message - We will deal with this as soon as possible")
' Or Divert to a thank you page.
End Sub
End Class
------------------------------------------------------------------
Also in the Web.Config File
<system.net>
<mailSettings>
<smtp deliveryMethod="network" from="
[email protected]">
<network host="mail.yourhost.com" userName="yourusername" password="xxxxx" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
-----------------------
Good Luck