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

 

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

Try

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”
objSMTPClient.Send(objMailMsg)

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
txtBody.Clear()
txtFrom.Clear()
txtTo.Clear()
txtSubject.Clear()
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,

Priya.

 

Advertisements

One Response to Sending e-mail using smtp mail(VB.Net)

  1. Superb post however , I was wondering if you could write a litte
    more on this topic? I’d be very thankful if you could elaborate a little bit further. Many thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: