A Simple Gmail Client

In This Post I will Guide u To making a Simple Gmail Client  to send Your Emails using Gmail Account Using Vb.net

 Let me Show You how final Result will Look Like:

1. For Sending Mail Through Vb.net. This Client Uses  “Imports System.Net.Mail”.
    So First Import it to your Code

Imports System.Net.Mail

2. Layout All the Controls As Shown In the Above Figure

3. There is Progress Bar after the send Button. I have used Backgroud Worker To Send the Mail. So that When Mail Sending is in Progress the Screen Wont Stop Working.

4. Now Here is the Complete Code

First Define This In your Form

Dim msg As New MailMessage 
Dim i As Integer

Form’s Load Event

Me.ProgressBar1.MarqueeAnimationSpeed = 0

Write This to Send Button’s Click Event

msg.From = New MailAddress(Me.txtuser.Text)
msg.Subject = Me.txtsubject.Text
msg.Body = Me.txtbody.Text
'' for attachment
For i = 0 To Me.ListBox1.Items.Count - 1
msg.Attachments.Add(New Attachment(Me.ListBox1.Items(i).ToString))
Me.Button1.Enabled = False
Me.Button1.Text = "Sendign.."
Me.ProgressBar1.Visible = True
Me.ProgressBar1.MarqueeAnimationSpeed = 100

Attach Button’s Click Event ( Button beside the listbox)

Dim d As New OpenFileDialog 
Me.ListBox1.Visible = True

Now its the Back Ground Worker …
Background worker’s Do work Event:

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork 

Dim i As Integer = 0
Dim smtp As New SmtpClient
smtp.Host = "smtp.gmail.com"
smtp.EnableSsl = True
smtp.Port = 587
smtp.Timeout = 300000
smtp.Credentials = New Net.NetworkCredential(Me.txtuser.Text, Me.txtpass.Text)
'Dim ms As MailMessage
'ms = e.Argument
' Label5.Text = "Sending Message......."
'Me.Button1.Text = "Sending...."
' Me.Button1.Enabled = False
e.Result = "Done"
Catch ex As Exception
'Label5.Text = "Sending Failed........"
End Try

Background Worker’s Run work Completed Event:

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted 
' Label5.Text = "Message Sending Complete"
Me.ProgressBar1.MarqueeAnimationSpeed = 0
Me.Button1.Text = "Send"
Me.Button1.Enabled = True
End Sub

And It’s Done.

For Complete Project Email me at [email protected]


2 thoughts on “A Simple Gmail Client

  1. I was looking for more information on Gmail
    and stumbled on sparekh.com. I just want to thank
    you for the information in this article. I am also working on a gmail tutorial right

Leave a Reply

Your email address will not be published. Required fields are marked *