Sitesbuilders.com
Write For US
Skip Navigation LinksHome > Using ASP.NET 2.0 To Send Email

Send Email From ASP.NET 2.0

The most common way of communication for both personal and business purposes through a web site is the contact us form. If you post just your email address on your site you immediately expose yourself to an honorable bulk of spam from all kinds in your mailbox.

Using ASP.net 2.0 you can send email through your contact form by using namespace called System.Web.Mail. Use the Send() method of SMTP class.
See the following appropriate code behind in order to send an email through your form.

Imports System.Net.Mail

Protected Sub doSendMail(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles SubmitBtn.Click

Dim rightNow As DateTime = DateTime.Now
Dim StrDay As String = rightNow.ToString("d")
Dim timenow As String = rightNow.ToString("HH:mm:ss")
Dim Name As String = Name.Text
Dim Phone As String = Phone.Text
Dim Email As String = Email.Text
Dim Message As String = Message.Text
Dim mMailMessage As New MailMessage()

' Set the sender address of the mail message
mMailMessage.From = New MailAddress(Email)
' Set the recepient address of the mail message
mMailMessage.To.Add(New MailAddress("xxx@xxxxx.xx"))
' Set the subject of the mail message
mMailMessage.Subject = "Contact Us"
' Set the body of the mail message
mMailMessage.Body = " Your HTML code "
' Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = True
' Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal
' Instantiate a new instance of SmtpClient
Dim mSmtpClient As New SmtpClient()
' Send the mail message
mSmtpClient.Send(mMailMessage)
End Sub

Contact Us   Add Your Site  Open Directory  Teomim.net

Powered by ASP.NET 2.0    Valid XHTML 1.0 Transitional   Scripts.com