I've taken over a project, and after sending an email, the details are supposed to be logged along with whether or not the email send was successful.
However, I noticed that the subroutine to log the data is never being called. So, I tried to include this in the bottom of the email send code like so
Smtp_Server.Send(e_mail) ' Here, Smtp_Server is System.Net.Mail.SmtpClient
' e_mail is System.Net.Mail.MailMessage
sendComplete(Me, New AsyncCompletedEventArgs) ' This is the call for the log subroutine
However, the bottom line gives the error:
'Public Sub New()' is obsolete: 'This API supports the .NET framework infrastructure and is not intended to be used directly from your code
This is the start of the sendComplete
subroutine.
Public Sub sendComplete(ByVal sender As Object, e As AsyncCompletedEventArgs)
Try
If e.Error IsNot Nothing Then
PictureBox1.Visible = False
MsgBox("Failed to send email!", MessageBoxIcon.Warning + MsgBoxStyle.OkOnly, "Error")
mailSent = True
What do I need to put into the second parameter to make the code call the subroutine? Or does the sendComplete
subroutine itself need changing?
EDIT
After adding the following Try...Catch
statement to the code, as suggested, the code executes fine and doesn't hit the Catch
, however, after sending the message, doesn't go to the sendComplete
subroutine.
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(senderAdd, senderPass)
Smtp_Server.EnableSsl = False
Smtp_Server.Host = SMTPserver
Try
AddHandler Smtp_Server.SendCompleted, AddressOf sendComplete
Catch ex As Exception
silentErrorLog(ex)
End Try