VB.Net SmtpServer.Send(mail)(Winform)在程序关闭之前不发送电子邮件. [英] VB.Net SmtpServer.Send(mail) (Winform) not sending email until program closes.

查看:81
本文介绍了VB.Net SmtpServer.Send(mail)(Winform)在程序关闭之前不发送电子邮件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编写的程序非常有效.发生某些情况时,它将发送电子邮件.

我遇到的问题是,直到我关闭程序后才发送电子邮件.不确定如何使电子邮件立即发送.
任何帮助将不胜感激.

这是代码:

I have a program I have written that works great. It sends an email when something occurs.

The problem I am running into is the email isn''t sent until after I close the program. Not sure how to make the email send immediately.
Any assistance would be greatly appreciated.

Here is the code:

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

推荐答案

我认为答案在这里:

http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx [ ^ ]

名为Russ的人也遇到了同样的问题,并想出了办法:
I think the answer is here:

http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx[^]

Someone named Russ has the same problem and figured it out:
如果有人感兴趣,我跟踪了上面提到的system.net.mail问题的原因,直到应用程序结束才发送外发消息.

事实证明,这与我在计算机上运行的Symantec AntiVirus(完整版本9.0.0.338)有关.通过关闭"Internet电子邮件自动防护"功能,我可以消除此问题.将其重新打开会导致相同的发送延迟.使用system.web.mail命名空间不会出现此问题(尽管IDE会警告它已过时.)
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.)


这篇关于VB.Net SmtpServer.Send(mail)(Winform)在程序关闭之前不发送电子邮件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆