I want to email the contents of my list view using the following code
What changes do i need to make to the FOR loop part for this to work? Anyone? :confused:
Code:
Private Sub btnEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmail.Click
Try
Dim strBody As String = ""
Dim SmtpServer As New SmtpClient
Dim mail As New MailMessage
Dim EmailTo As String
Dim i As Integer
EmailTo = InputBox("Who would you like to send this to?")
SmtpServer.EnableSsl = True '' needed for gmail
SmtpServer.UseDefaultCredentials = False '' needed for gmail
SmtpServer.Credentials = New Net.NetworkCredential("myemail@gmail.com", "password") ' you need your ISP login credentials
SmtpServer.Port = 587 ' usually port 25
SmtpServer.Host = "smtp.gmail.com" ' or your ISP SMTP server
mail = New MailMessage
mail.From = New MailAddress("myemail@gmail.com")
mail.To.Add(EmailTo)
mail.Subject = "Your Order Receipt"
For i = 0 To ListViewOrder.SelectedItems.Count - 1
If ListViewOrder.SelectedItems.Count > 0 Then
strBody += ListViewOrder.SelectedItems(i).SubItems(0).ToString & vbCrLf
strBody += ListViewOrder.SelectedItems(i).SubItems().ToString & vbCrLf
End If
Next
mail.Body = strBody
SmtpServer.Send(mail)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub