A common thing you will need to do with ASP.Net v 2.0, is to send
emails, I will show you here how to send emails using ASP.Net v 2.0,
implementing authentication
The namespace for sending mail within ASP.Net v 2.0 is not System.Web.Mail anymore this was replaced by System.Net.Mail
You can use just three lines of code to send emails,
Dim SmtpClient As New System.Net.Mail.SmtpClient
SmtpClient.Host = “localhost”
SmtpClient.Send(from,to,subject,body)
This will send your email assuming your SMTP server is “localhost”,
change this to your real SMTP host, probably “mail.yourdomain.com”
If your SMTP server requires authentication then you will need to add one line of code so your code will be
Dim SmtpClient As New System.Net.Mail.SmtpClient
SmtpClient.Host = “localhost”
SmtpClient.Credentials = New NetworkCredential( "username" , "password" )
SmtpClient.Send( "fomemail" ,toemail,subject,body)
While this will send your emails, you can feather specify more details
like HTML body, encoding and all the other cool things, I have a sub
routine that encapsulate this code so it can be reused
Sub Send( ByVal emailFrom As String , ByVal emailTo As String , ByVal emailSubject As String , ByVal emailMessage As String , ByVal isBodyHTML As Boolean )
Dim msgMail As New System.Net.Mail.MailMessage
Dim emailFromAddress As New System.Net.Mail.MailAddress(emailFrom)
Dim emailToAddress As New System.Net.Mail.MailAddress(emailTo)
Dim SmtpClient As New System.Net.Mail.SmtpClient
msgMail.To(0) = emailToAddress
msgMail.From = emailFromAddress
msgMail.Subject = emailSubject
msgMail.IsBodyHtml = isBodyHTML
msgMail.Body = emailMessage
SmtpClient.Host = "localhost"
SmtpClient.Credentials = New NetworkCredential( "username" , "password" )
SmtpClient.Send(msgMail)
End Sub
Hope this will help,