我有一个列表框,可以从filesystemwatcher获取其项目。每次将项目添加到列表框时,我希望能够逐个自动通过电子邮件发送项目。这是我的代码问题,只有第一项是通过电子邮件发送
Private Sub FileSystemWatcher1_Created(sender As Object, e As FileSystemEventArgs) Handles FileSystemWatcher1.Created
If DeimosRadioButton1.Enabled = True Then
ListBox1.Items.Add(e.FullPath.ToString)
Label2.Hide()
If ListBox1.Items.Count > 0 Then
Dim Counter As Integer = 0
Dim Mail As New MailMessage
Mail.Subject = "HACK REPORT!"
Mail.To.Add("@gmail.com")
Mail.From = New MailAddress("@gmail.com")
Mail.Body = "Proof is attached in this email"
Dim Attachment As System.Net.Mail.Attachment
Attachment = New Attachment(ListBox1.Items(Counter).ToString)
Mail.Attachments.Add(Attachment)
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(Label4.Text, Label5.Text)
SMTP.Port = "587"
SMTP.Send(Mail)
End If
End If
End Sub
答案 0 :(得分:0)
由于plutonix声明你的COUNTER永远不会增加,因为它不是任何形式的FOR / NEXT或DO / LOOP
Private Sub FileSystemWatcher1_Created(sender As Object, e As FileSystemEventArgs) Handles FileSystemWatcher1.Created
'
If DeimosRadioButton1.Enabled = True Then
ListBox1.Items.Add(e.FullPath.ToString)
Label2.Hide()
If ListBox1.Items.Count > 0 Then
Dim Counter As Integer = 0
For Counter = 0 to Listbox1.Items.Count - 1
Dim Mail As New MailMessage
Mail.Subject = "HACK REPORT!"
Mail.To.Add("@gmail.com")
Mail.From = New MailAddress("@gmail.com")
Mail.Body = "Proof is attached in this email"
'
Dim Attachment As System.Net.Mail.Attachment
'
Attachment = New Attachment(ListBox1.Items(Counter).ToString)
Mail.Attachments.Add(Attachment)
'
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(Label4.Text, Label5.Text)
SMTP.Port = "587"
SMTP.Send(Mail)
'DoEvents/Yield system time to the sending or other events
Next
End If
End If
'
End Sub