【发布时间】:2015-08-21 00:02:08
【问题描述】:
我有一个从文件系统观察器获取其项目的列表框。每次将项目添加到列表框时,我希望能够自动通过电子邮件将项目一一发送。这是我的代码问题是只有第一个项目是通过电子邮件发送的
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
【问题讨论】:
-
如果在将文件名添加到列表框之前通过电子邮件发送文件名(
e.FullPath- 不需要 ToString),则无需跟踪任何内容。 FSW 在其自己的线程上运行,因此您可以将项目#10 发送两次,而从不发送#9。照原样,Counter始终为零并发送第一项
标签: .net vb.net visual-studio-2010