Sending a email using ASP.NET 2.0 and VB.NET is actually very simple.
First, you will need to import the System.Net.Mail namespace.
The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email.
We use the btnSubmit_Click event to do the work.
We then call the emailClient.Send to send the message using the variables from our ASP.NET coded page.
We then call the emailClient.Send to send the message using the variables from our ASP.NET coded page.
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
End SubDim message As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)
litStatus.Text = "Message Sent"
Catch ex As ExceptionDim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)
litStatus.Text = "Message Sent"
litStatus.Text = ex.ToString()
End Try
No comments:
Post a Comment