Sending e-mail using smtp mail(VB.Net)

May 2, 2008


In Dotnet, System.Net.Mail namespace provides the classes for sending e-mails. The code given below is the sample.
Imports System
Imports System.Net.Mail
Public Class Form1
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click


Dim objMailMsg As MailMessage = New MailMessage(txtFrom.Text, txtTo.Text)

objMailMsg.Subject = txtSubject.Text
objMailMsg.Body = txtBody.Text
objMailMsg.Priority = MailPriority.High
objMailMsg.IsBodyHtml = True

Dim objSMTPClient As Net.Mail.SmtpClient = New Net.Mail.SmtpClient()

objSMTPClient.Host = “your host address”

Catch ex As Exception
Throw ex
End Try

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
End Sub

End Class

 For the above code to work, Create a new VB.Net windows application project, and design a form with From, To, Subject, Body fields And Send, Clear  Buttons.

Most importantly, Dont forget to add the System.Web.dll reference (right click on project -> Add Reference -> Browse for the System.Web.dll reference.

Happy Working. See you later…

Till then,