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.MailMessageMy_Mail.To.Add(ToAdd)
My_Mail.From = FromAddress
My_Mail.Subject = Subject
My_Mail.Body = Body
If HTML ThenMy_Mail.IsBodyHtml =
True ElseMy_Mail.IsBodyHtml =
False End If If Attachments <> "" ThenTempAttachments = Split(Attachments, Chr(0))
For Each TempAttachment In TempAttachments If TempAttachment <> "" ThenMy_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 ThenShowMessageWindow(
"Send E-Mail...", "Sending to:-" & vbCrLf & vbCrLf & ToAdd) End IfSend_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 StringSubject =
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
Strange smtpclient.send behavior
Ripster