25-Emailing Application


This tutorial is all about Emailing Application.

In my previous tutorial, we learn how to send an email. This time, we will learn here how to create a Sending Mail application in Visual basic 2008 .



Here’s the example on how to create a Sending Mail application.

  1. Open the Visual Basic, select “File” on the menu, hit new and create a new project.
  2. The New Project dialog will appear.
    Select “windows” in the project types, hit the “windows form application” in the templates and hit “ok“.
  3. Design the form this way. See it Below.
    24-send email
  4. Double click the button to fire the event handler of it and do this following code.
    1. Imports System.Net.Mail
    2. Public Class Form1Private Sub btnsend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsend.Click
    3. Try
    4. Dim SmtpServer As New SmtpClient
    5. Dim Semail As New MailMessage()
    6. SmtpServer.UseDefaultCredentials = False
    7. SmtpServer.Credentials = New Net.NetworkCredential("[email protected]", "password")
    8. SmtpServer.Port = 587
    9. SmtpServer.EnableSsl = True
    10. SmtpServer.Host = "smtp.gmail.com"Semail = New MailMessage()
    11. Semail.From = New MailAddress(txtFrom.Text)
    12. Semail.To.Add(txtTo.Text)
    13. Semail.Subject = "Sending Email"
    14. Semail.IsBodyHtml = False
    15. Semail.Body = txtMsg.Text
    16. SmtpServer.Send(Semail)
    17. MsgBox("Mail already sent.")Catch ex As Exception
    18. MsgBox(ex.Message)
    19. End TryEnd Sub

Provide gmail address and real password for credentials.



Readers might read also:




Facebook Comments


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.