This module is used in quite a few places to handle errors
Sub globalErrorHandler(ByVal ex As Exception)
'log the error
Dim strMsg As String = ""
strMsg += "Exception: " + vbCrLf
strMsg += ex.Message + vbCrLf
''display the error
'If strMsg.Contains("Illegal address") Then
' Exit Sub
'End If
strMsg += "GetType: " & ex.GetType().FullName + vbCrLf
strMsg += "Source: " & ex.Source + vbCrLf
strMsg += "StackTrace: " & ex.StackTrace + vbCrLf
strMsg += "TargetSite: " + ex.TargetSite.ToString & vbCrLf
If Not ex.InnerException Is Nothing Then
strMsg += "Inner Exception: " & vbCrLf
strMsg += ex.InnerException.Message + vbCrLf
strMsg += "GetType: " & ex.InnerException.GetType().FullName + vbCrLf
strMsg += "Source: " & ex.InnerException.Source + vbCrLf
strMsg += "StackTrace: " & ex.InnerException.StackTrace + vbCrLf
strMsg += "TargetSite: " + ex.InnerException.TargetSite.ToString & vbCrLf
End If
strMsg += appUser.UserID
'mail the error
sendMail(strMsg)
globalMessageBox(strMsg)
End Sub
Sub globalMessageBox(ByVal strMessage As String)
MsgBox(strMessage, , "Dynamics GP")
End Sub
Public Sub sendMail(ByVal strBody As String)
Try
Dim strEmailServer As String = System.Configuration.ConfigurationManager.AppSettings("emailServer")
Dim strEmailUser As String = System.Configuration.ConfigurationManager.AppSettings("emailUser")
'Dim strEmailPassword As String = System.Configuration.ConfigurationManager.AppSettings("emailPassword")
Dim strEmailRecipient As String = System.Configuration.ConfigurationManager.AppSettings("emailRecipient")
Dim mail As New System.Net.Mail.MailMessage(strEmailUser, strEmailRecipient)
mail.Subject = "NGB Dynamics VS Tools Error"
mail.Body = strBody
Dim serv As New System.Net.Mail.SmtpClient(strEmailServer)
'serv.Credentials = New System.Net.NetworkCredential(strEmailUser, strEmailPassword)
serv.Send(mail)
Catch ex As Exception
globalMessageBox("Failed to send Admin Email")
'no error handling. we're already in an error loop. If this fails, we're just out of luck
End Try
End Sub
You'll need the email settings in the app.config
<appSettings>
<add key="emailServer" value="mail.domain.com" />
<add key="emailUser" value="emailuser" />
<add key="emailRecipient" value="emailrecipient" />
<add key="emailPassword" value="abcd1234" />
</appSettings>