I am working on a program that lets you add student emails and their grade and it will email them all with their grade in the body of the email. I have it where you add a student email and grade into a listview and then I have a loop that goes through it and emails each one. This works, but with only one email in the listview. My code is below, if anyone has any ideas on how to fix this let me know. I have not programmed in VB in 4 years and this program will help me out allot. I also attached an image of my 2 forms. I think the problem is that in my loop, it is not advancing to the next row to get the next email, instead I think that it is trying to email to the grade and crashing.
This is my first post so hopefully I did everything correctly.
Pictures of forms: http://i47.tinypic.com/20k59qq.jpg
This is my first post so hopefully I did everything correctly.
Imports System.Net.Mail Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim mail As New MailMessage mail.Subject = (TextBox5.Text) mail.From = New MailAddress(TextBox2.Text) Dim smtp As New SmtpClient("Smtp.gmail.com") smtp.EnableSsl = True smtp.Credentials = New System.Net.NetworkCredential(TextBox2.Text, TextBox3.Text) smtp.Port = "587" If Me.ListView1.Items.Count <> 1 Then Exit Sub Dim row As ListViewItem = Me.ListView1.Items(0) Dim values(0 To row.SubItems.Count - 1) As String Dim i As Integer = 0 For Each item As ListViewItem.ListViewSubItem In row.SubItems values(i) = item.Text mail.To.Add(item.Text) For Each item2 As ListViewItem.ListViewSubItem In row.SubItems mail.Body = "Grade: " + item2.Text Next smtp.Send(mail) i = i + 1 Next MessageBox.Show("Done!", "Emailer", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub
Pictures of forms: http://i47.tinypic.com/20k59qq.jpg
