Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Windows App. Vb.net 2008

I have a form to send mail using gmail id with attachments

what i am doing is i am sending my zip file to gmail id ,

now i want to show a progress bar to user when sending mail and after
send mail i want to show a msg Like Success as boolean , mail send or not

here is my code to send mail.
========
VB
Imports System.Net.Mail

Public Class FrmSendMail
Dim mail As New MailMessage()

Private Sub FrmSendMail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ProgressBar1.MarqueeAnimationSpeed = 0
        txtsubj.Text = "Sending Data"
        txtfrom.Text = "nagcm2brd@gmail.com"
        txtto.Text = "nagcm1hyd@gmail.com"
        Dim pwd As String
        pwd = "ayub1234"
        If InternetConnection() = False Then
            MessageBox.Show("No internet connection!", "Connecting to Internet", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.Btnclose_Click(sender, e)
        Else
            MessageBox.Show("Internet connection detected!", "Connecting to Internet", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

Private Sub sendml()
        Dim SmtpServer As New SmtpClient()

        SmtpServer.Credentials = New Net.NetworkCredential("nagcm2brd@gmail.com", "ayub1234")
        SmtpServer.Port = 587
        SmtpServer.Host = "smtp.gmail.com"
        SmtpServer.EnableSsl = True

        mail = New MailMessage()
        Dim addr() As String = txtto.Text.Split(",")
        Try
            mail.From = New MailAddress("nagcm2brd@gmail.com", "Baroda Data", System.Text.Encoding.UTF8)

            Dim i As Byte
            For i = 0 To addr.Length - 1
                mail.To.Add(addr(i))
            Next
            mail.Subject = txtsubj.Text
            mail.Body = txtmsg.Text
            If ListBox1.Items.Count <> 0 Then
                For i = 0 To ListBox1.Items.Count - 1
                    mail.Attachments.Add(New Attachment(ListBox1.Items.Item(i)))

                Next
            End If

            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
            mail.ReplyTo = New MailAddress(txtto.Text)
            SmtpServer.Send(mail)


        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try
    End Sub

 Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
        sendml()
    End Sub
End Class
========

Any Help will be highly appreciated.
Thanks in advance.
Posted
Updated 15-Feb-12 21:33pm
v2

a small google search leads to this[^].
 
Share this answer
 
Comments
gufran90 16-Feb-12 3:44am    
Thanks for your reply , @digimanus

i have read the msdn link but its ,
showing answer with third party tool ( Chilkat.net )

is there any way to do with vb.net only

waiting for your reply.

Thanks in advance
Herman<T>.Instance 16-Feb-12 3:50am    
without that component it lloks like it cannot be done.
Progressbar is only useful when sending large attachments.
Other optios is sending a stream to a socket. The stream can can be send in parts and counting the parts leads to a percentage.
gufran90 16-Feb-12 4:14am    
Thanks for your quick response @digimanus ,

ok , leave progress bar ,
i want to confirm to user the mail was send or not ,

how can i do that .

thanks is advance
waiting for your reply.

Where is InternetConnection()funtion's method?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900