Merge branch 'master' of http://dd-vmp07-com04:3000/AppStd/Monorepo
This commit is contained in:
@@ -14,10 +14,8 @@ Public Class EmailService
|
||||
Private _MSSQL_Test As MSSQLServer
|
||||
Private _Email As Email
|
||||
Private _Encryption As EncryptionLegacy
|
||||
|
||||
Private _EmailQueue As BackgroundWorker
|
||||
Private _QueueTimer As Timer
|
||||
|
||||
Private _AnyDatabaseInitialized As Boolean = False
|
||||
|
||||
Private Enum DatabaseType
|
||||
@@ -28,7 +26,6 @@ Public Class EmailService
|
||||
Protected Overrides Sub OnStart(ByVal args() As String)
|
||||
Try
|
||||
' === Initialize Logger ===
|
||||
|
||||
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "EmailService")
|
||||
_LogConfig.Debug = My.Settings.DEBUG
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
@@ -203,7 +200,7 @@ Public Class EmailService
|
||||
End If
|
||||
|
||||
Dim oEmailTo, oSubject, oBody As String
|
||||
Dim oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment, ofromName
|
||||
Dim oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment, ofromName, oErrorMsg
|
||||
Dim oAccountId, oGuid, oJobId As Integer
|
||||
|
||||
For Each oEmailToRow As DataRow In oEmailQueue.Rows
|
||||
@@ -216,7 +213,7 @@ Public Class EmailService
|
||||
Case DatabaseType.MSSQL
|
||||
oAccountId = oEmailToRow.Item("SENDING_PROFILE")
|
||||
End Select
|
||||
|
||||
oErrorMsg = ""
|
||||
For Each oAccountRow As DataRow In oEmailAccounts.Rows
|
||||
If oAccountRow.Item("GUID") = oAccountId Then
|
||||
oAccountMatch = True
|
||||
@@ -239,6 +236,12 @@ Public Class EmailService
|
||||
oMailUser = oAccountRow.Item("EMAIL_USER")
|
||||
oAuthType = oAccountRow.Item("AUTH_TYPE")
|
||||
oMailPW = oAccountRow.Item("EMAIL_PW")
|
||||
Try
|
||||
oErrorMsg = IIf(IsDBNull(oAccountRow.Item("ERROR_MSG")), "", oAccountRow.Item("ERROR_MSG"))
|
||||
Catch ex As Exception
|
||||
oErrorMsg = ""
|
||||
End Try
|
||||
|
||||
End Select
|
||||
|
||||
Dim oPasswordPlain = _Encryption.DecryptData(oMailPW)
|
||||
@@ -260,6 +263,9 @@ Public Class EmailService
|
||||
|
||||
Return False
|
||||
End If
|
||||
If oErrorMsg <> String.Empty Then
|
||||
|
||||
End If
|
||||
|
||||
Select Case Database
|
||||
Case DatabaseType.Firebird
|
||||
@@ -288,13 +294,16 @@ Public Class EmailService
|
||||
End Select
|
||||
|
||||
If oAttachment <> String.Empty Then
|
||||
If IO.File.Exists(oAttachment) = False Then
|
||||
_Logger.Warn($"Email Attachment FB FileNotFound Exception!")
|
||||
oComment = "Email Attachment FB FileNotFound Exception"
|
||||
oAttachment = String.Empty
|
||||
Else
|
||||
_Logger.Debug("Email Attachment is: {0}", oAttachment)
|
||||
If oAttachment.ToString.Contains("\") Then
|
||||
If IO.File.Exists(oAttachment) = False Then
|
||||
_Logger.Warn($"Email Attachment [{oAttachment}] not existing!")
|
||||
oComment = $"Email Attachment [{oAttachment}] not existing!"
|
||||
oAttachment = String.Empty
|
||||
Else
|
||||
_Logger.Debug("Email Attachment is: {0}", oAttachment)
|
||||
End If
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Dim oEmailSent As Boolean = False
|
||||
@@ -316,8 +325,39 @@ Public Class EmailService
|
||||
End If
|
||||
MSSQLInstance.ExecuteNonQuery(oSQL)
|
||||
End Select
|
||||
_Logger.Info($"Email has been send to: {oEmailTo} - Subject: {oSubject}")
|
||||
_Logger.Info($"EmailID [{oGuid.ToString}] has been send to: {oEmailTo}")
|
||||
Threading.Thread.Sleep(500)
|
||||
Else
|
||||
Select Case Database
|
||||
'Case DatabaseType.Firebird
|
||||
' oSQL = $"UPDATE TBEDM_EMAIL_QUEUE SET EMAIL_SENT = CURRENT_TIMESTAMP,COMMENT = '{oComment}' WHERE GUID = {oGuid}"
|
||||
' If oSQL.Contains(",COMMENT = ''") Then
|
||||
' oSQL.Replace(",COMMENT = ''", "")
|
||||
' End If
|
||||
' _Firebird.ExecuteNonQuery(oSQL)
|
||||
Case DatabaseType.MSSQL
|
||||
oSQL = $"UPDATE TBEMLP_EMAIL_OUT SET ERROR_TIMESTAMP = GETDATE(),ERROR_MSG = '{_Email.Err_Message}' WHERE GUID = {oGuid} "
|
||||
MSSQLInstance.NewExecutenonQuery(oSQL)
|
||||
If _Email._msg_Send = True Then
|
||||
Select Case Database
|
||||
Case DatabaseType.Firebird
|
||||
oSQL = $"UPDATE TBEDM_EMAIL_QUEUE SET EMAIL_SENT = CURRENT_TIMESTAMP,COMMENT = '{oComment}' WHERE GUID = {oGuid}"
|
||||
If oSQL.Contains(",COMMENT = ''") Then
|
||||
oSQL.Replace(",COMMENT = ''", "")
|
||||
End If
|
||||
_Firebird.ExecuteNonQuery(oSQL)
|
||||
Case DatabaseType.MSSQL
|
||||
oSQL = $"UPDATE TBEMLP_EMAIL_OUT SET EMAIL_SENT = GETDATE(),COMMENT = '{oComment}' WHERE GUID = {oGuid} "
|
||||
If oSQL.Contains(",COMMENT = ''") Then
|
||||
oSQL.Replace(",COMMENT = ''", "")
|
||||
End If
|
||||
MSSQLInstance.NewExecutenonQuery(oSQL)
|
||||
End Select
|
||||
_Logger.Info($"EmailID [{oGuid.ToString}] has been send to: {oEmailTo} - althogh there was an error in connection close!")
|
||||
|
||||
End If
|
||||
|
||||
End Select
|
||||
End If
|
||||
Next
|
||||
|
||||
|
||||
Reference in New Issue
Block a user