Strange smtpclient.send behavior

Hi, i am triyng to send some E-Mails from my application. When i was using it in 1.1 the E-Mails would go instantly after calling the .send(MyMail) but under 2.0 the E-mails dont go until the application has closes.... any one know why this would happen

Do i have to set the SMTPClient class to nothing befor it will send the E-Mails etc

Im finding this a little strange

------------- Code for sending the E-Mail -----------------------

Function SendEmailNow(ByVal From As String, ByVal ToAdd As String, ByVal Subject As String, ByVal Body As String, ByVal HTML As Boolean, ByVal DBConnection As SqlClient.SqlConnection, ByVal StealthSend As Boolean, Optional ByVal LinkID As String = "", Optional ByVal Attachments As String = "") As Boolean

Dim Send_Mail As SmtpClient = New SmtpClient(SMTPServer)

Dim My_Mail As System.Net.Mail.MailMessage

Dim My_Attachment As System.Net.Mail.Attachment

Dim FoundError As Boolean = False

Dim TempAttachments() As String

Dim TempAttachment As String

Dim FromAddress As Net.Mail.MailAddress = New Net.Mail.MailAddress(From, From)

'=================================================

'== Set Up New E-Mail ==

'=================================================

My_Mail = New System.Net.Mail.MailMessage

My_Mail.To.Add(ToAdd)

My_Mail.From = FromAddress

My_Mail.Subject = Subject

My_Mail.Body = Body

If HTML Then

My_Mail.IsBodyHtml = True

Else

My_Mail.IsBodyHtml = False

End If

If Attachments <> "" Then

TempAttachments = Split(Attachments, Chr(0))

For Each TempAttachment In TempAttachments

If TempAttachment <> "" Then

My_Attachment = New System.Net.Mail.Attachment(TempAttachment)

My_Mail.Attachments.Add(My_Attachment)

End If

Next

End If

'====================================================

'== Try To Send The E-Mail, if it Fails Log Event ==

'====================================================

Try

If StealthSend = False Then

ShowMessageWindow("Send E-Mail...", "Sending to:-" & vbCrLf & vbCrLf & ToAdd)

End If

Send_Mail.Send(My_Mail)

Catch ex As Exception

Me.LogEvent(DBConnection, "Failed E-Mail Error Message", ex.Source & " - " & ex.Message, "ERROR", System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"))

Me.LogEvent(DBConnection, "Failed E-Mail Sent To", ToAdd, "ERROR", System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"))

MsgBox(ex.Message)

FoundError = True

End Try

'=================================================

'== If There is a LinkID, Save The E-Mail ==

'=================================================

If Not FoundError And LinkID <> "" Then

Dim SQL As String

Subject = Me.ReplaceForDB(Subject)

Body = Me.ReplaceForDB(Body)

SQL = "Insert Into EmailsTable (ID,LinkID,DateTimeSent,[To],[From],[Subject],[Body],[HTML],[Sent], Attachments) Values ('" & Me.Get_Cripto("EMAIL") & "', '" & LinkID & "','" & System.DateTime.Now.ToString("MM/dd/yyyy HH:mm") & "', '" & ToAdd & "', '" & From & "', '" & Subject & "', '" & Body & "', '" & Int(HTML) & "', 1, '" & Attachments & "')"

Me.UpdateDatabase(SQL, DBConnection)

End If

End Function



Answer this question

Strange smtpclient.send behavior

  • Ripster

    still no joy, any one got any idears
  • Strange smtpclient.send behavior