VB.NET 2005 - SMTP Sends After Program Close

HardCode

Well-known member
Joined
Apr 2, 2004
Messages
49
I am using the following Private Sub of a class to send e-mail. My company uses Norton to scan outgoing e-mails. This function, in VB.NET 2003, used System.Web.Mail, from a Windows Application, and sent the e-mails immediately. Now, using it in VB.NET 2005 and System.Net.Mail, the e-mails do not get sent until I close the program to which this class belongs (being run in both Debug configuration via the IDE and the compiled .EXE). Its very strange. I have no idea how or why the e-mails would be caching somewhere until the program is closed. I know this is happening, because after I close the program, Norton lights up the System Tray like fireworks, for each e-mail being sent.

Code:
Private Sub SendInvite(ByVal Subject As String, ByVal Body As String, ByVal SendTo As String, _
ByVal Link As String, ByVal Incentive As Integer, ByVal TimeText As String)
        Try
            Dim mailMessage As System.Net.Mail.MailMessage
            Dim mailFrom As System.Net.Mail.MailAddress
            Dim mailTo As System.Net.Mail.MailAddress
            Dim mailSMTP As System.Net.Mail.SmtpClient

            Subject = Replace(Subject, "<SNIP>", TimeText)

            Body = Replace(Body, "<Link>", Space(5) & Link)
            Body = Replace(Body, "<Incentive>", Incentive.ToString)
            Body = Replace(Body, "<TimeText>", TimeText)

            mailFrom = New System.Net.Mail.MailAddress("<SNIP>", "<SNIP>")
            mailTo = New System.Net.Mail.MailAddress(SendTo)
            mailMessage = New System.Net.Mail.MailMessage(mailFrom, mailTo)
            mailMessage.Subject = Subject
            mailMessage.BodyEncoding = System.Text.Encoding.UTF8
            mailMessage.Body = Body

            mailSMTP = New System.Net.Mail.SmtpClient(sSmtpServer)
            mailSMTP.Send(mailMessage)

        Catch ex As Exception
            Throw (ex)
        End Try
    End Sub

Variable sSmtpServer is a Private class-level variable assigned by a Public Property of the class.
 
Try turning of Norton and running the test again, does it still wait for the app to exit or are the mails sent straight away?

Only mentioning this as Ive encountered problems in the past with this kind of thing and it turned out to be the AV product.
 
Back
Top