Sending E-mail using VB.NET

Hi! In this tutorial, i will introduce some kind advanced VB.NET Tutorial which is Sending an E-mail. VB.Net allows sending e-mails from your application. The System.Net.Mail namespace contains classes used for sending e-mails to a Simple Mail Transfer Protocol (SMTP) server for delivery. In this tutorial, let us create a simple application that would send an e-mail. Take the following steps:
  1. Add three labels, three text boxes and a button control in the form.
  2. Change the text properties of the labels to - 'From', 'To:' and 'Message:' respectively.
  3. Change the name properties of the texts to txtFrom, txtTo and txtMessage respectively.
  4. Change the text property of the button control to 'Send'
  5. Add the following code in the code editor.
The interface will be like this: First Run Next, type the following code:
  1. Imports System.Net.Mail
  2. Public Class Form1
  3.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
  4.         ' Set the caption bar text of the form.  
  5.         Me.Text = "www.sourcecodester.com"
  6.     End Sub
  7.  
  8.     Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  9.         Try
  10.             Dim Smtp_Server As New SmtpClient
  11.             Dim e_mail As New MailMessage()
  12.             Smtp_Server.UseDefaultCredentials = False
  13.             Smtp_Server.Credentials = New Net.NetworkCredential("[email protected]", "password")
  14.             Smtp_Server.Port = 587
  15.             Smtp_Server.EnableSsl = True
  16.             Smtp_Server.Host = "smtp.gmail.com"
  17.  
  18.             e_mail = New MailMessage()
  19.             e_mail.From = New MailAddress(txtFrom.Text)
  20.             e_mail.To.Add(txtTo.Text)
  21.             e_mail.Subject = "Email Sending"
  22.             e_mail.IsBodyHtml = False
  23.             e_mail.Body = txtMessage.Text
  24.             Smtp_Server.Send(e_mail)
  25.             MsgBox("Mail Sent")
  26.  
  27.         Catch error_t As Exception
  28.             MsgBox(error_t.ToString)
  29.         End Try
  30.  
  31.     End Sub
  32. End Class
The SmtpClient class allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP). Following are some commonly used properties of the SmtpClient class: Property Description
  1. ClientCertificates Specifies which certificates should be used to establish the Secure Sockets Layer (SSL) connection.
  2. Credentials Gets or sets the credentials used to authenticate the sender.
  3. EnableSsl Specifies whether the SmtpClient uses Secure Sockets Layer (SSL) to encrypt the connection.
  4. Host Gets or sets the name or IP address of the host used for SMTP transactions.
  5. Port Gets or sets the port used for SMTP transactions.
  6. Timeout Gets or sets a value that specifies the amount of time after which a synchronous Send call times out.
  7. UseDefaultCredentials Gets or sets a Boolean value that controls whether the DefaultCredentials are sent with requests.
The tutorial demonstrates how to send mail using the SmtpClient class. Following points are to be noted in this respect:
  • You must specify the SMTP host server that you use to send e-mail. The Host and Port properties will be different for different host server. We will be using gmail server.
  • You need to give the Credentials for authentication, if required by the SMTP server
  • You should also provide the email address of the sender and the e-mail address or addresses of the recipients using the MailMessage.From and MailMessage.To properties, respectively.
  • You should also specify the message content using the MailMessage.Body property
Now, try to type all the string value on your corresponding textboxes like this below. email sending And the result of this when clicking the button will be sent to your e-mail. Example is this image below that it was sent to my e-mail address. Result For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment