Public Sub File_Deleted(ByVal obj As Object, ByVal e As FileSystemEventArgs) Select Case e.ChangeType Case WatcherChangeTypes.Deleted If InStr(e.Name, ".") < 1 Then 'SendEmail(e.FullPath & " - Deleted") Dim SmtpServer As New SmtpClient() Dim mail As New MailMessage() 'SmtpServer.Credentials = New _ 'Net.NetworkCredential("username@gmail.com", "password") ' SmtpServer.Port = 587 'SmtpServer.Host = "smtp.gmail.com" SmtpServer.Host = "smtpserver" mail = New MailMessage() mail.From = New MailAddress("Joe@homesweethome.com") mail.To.Add("Joe@homesweethome.com") mail.Subject = e.FullPath & " - Deleted" mail.Body = "This is for testing SMTP mail" SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network SmtpServer.Send(mail) 'SmtpServer.SendAsync(mail, New Object) 'MsgBox("mail send") mail = Nothing SmtpServer = Nothing MsgBox(e.FullPath & " - Deleted") End If End Select End Sub
In case anyone is interested, I tracked down the cause of the problem I mentioned above with system.net.mail not sending outgoing messages until the application ends. It turned out being related to Symantec AntiVirus (Full version 9.0.0.338) that I have running on my machine. I was able to eliminate the problem by turning off the "Internet E-Mail Auto-Protect" feature. Turning it back on resulted in the same send delay. Using the system.web.mail namespace does not exhibit this problem (despite the IDE's warnings about it being obsolete.)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)