asp.net send mail with vb.net

Sending mail is with asp.net is simple, you can find it yourself with the next a few lines of code which are handled by button click event:

First importing the namespace:

Imports System.Net.Mail

Than the Handler code:

If Page.IsValid() Then

Dim mySmtpClient As New SmtpClient

Dim myMail As New MailMessage

Dim myFrom As New MailAddress("test@test.com")Dim myTo As New MailAddress("someone@test.com")

myMail.BodyEncoding = System.Text.Encoding.UTF8

myMail.To.Add(myTo)

myMail.From = myFrom

myMail.Subject = "Web mail"

myMail.Body = vbCrLf & vbCrLf & "Hi, my name is John Anderson. I'am interested in ..."

mySmtpClient.Host = ConfigurationManager.AppSettings("test.com")

mySmtpClient.Credentials =
New System.Net.NetworkCredential("webmaster@test.com", "password123", "test.com")

Try

mySmtpClient.Send(myMail)

lblAlert.Text = "Mail sending success message"

Catch ex As Exception

lblAlert.Text = "Mail sening fail"

End Try

End If

No Comments