Here is a small code for sending an email from ASP.NET 2.0 page, using the namespace System.net.mail and a Gmail account.
First of all we have to import these :
Imports
System.Net.Mail
Imports
System.Net.Mail.MailMessage
Imports
System.Net.NetworkCredential
Then,
Dim
mail As New MailMessage()
Dim msgBody As String
Dim smtp As New SmtpClient
mail.From = New MailAddress(“ur-gmail-account@gmail.com“, "display name")
mail.To.Add(“ur-email@host.com“)
mail.Subject = “Subject“
mail.Body = “msgBody“
mail.IsBodyHtml = True ' This is to enable HTML in your email body
mail.ReplyTo = New MailAddress(“reply-to-email-address“) ' This is optional, it allows you to add Reply To email address.
smtp.Host = "smtp.gmail.com"
smtp.Port = 25
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential(“ur-gmail-account@gmail.com“, "gmail-password")
smtp.Send(mail)
lblFlag.Text = "Your Message has beent sent."
Note: We can build this email form AJAX based, by putting the content in an UpdatePanel control, and add the button “send” as a trigger.
A.