0
Reply

vb.net email code using data from list box

Ask a question
stanley george

stanley george

12y
2.1k
1
hi, 
    i m working on a project and have used the code given below to take email address from listbox and send the information of that person as email.....but the result i m getting is not what i want ...in my code...the first mail id in the list gets one email of its information but as well as  other emails of information other people  below it also as  different emails.

i want that each id gets only its information as mail...

pls tell me the corrections its urget ...
thanx in advance

code:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Mail As New MailMessage
        Dim templv As ListViewItem
        Dim emailad As String = ""
        Dim smtp As New SmtpClient("smtp.gmail.com")
        smtp.EnableSsl = True
        smtp.Credentials = New System.Net.NetworkCredential("[email protected]", "XXXXXXXX")
        smtp.Port = 587

        For Each templv In ListView1.Items
            Dim co1 As String = templv.SubItems.Item(0).Text
            Dim co2 As String = templv.SubItems.Item(1).Text
            Dim co3 As String = templv.SubItems.Item(2).Text
            Dim co4 As String = templv.SubItems.Item(3).Text

            Mail.From = New MailAddress("[email protected]")
            Mail.To.Add(templv.SubItems.Item(3).Text)
            Mail.Subject = "test mail"
            Mail.Body = co1 & " " & co2 & " " & co3 & " " & co4


            smtp.Send(Mail)
        Next
        


        MsgBox("sent successfully", vbInformation, "thank you!")



    End Sub