EMailProfiler Common: Neue Ablehnungsmail-Logik
This commit is contained in:
@@ -118,6 +118,7 @@
|
||||
<Compile Include="clsWindream_Index.vb" />
|
||||
<Compile Include="clsWorkEmail.vb" />
|
||||
<Compile Include="clsWorker.vb" />
|
||||
<Compile Include="ErrorCode.vb" />
|
||||
<Compile Include="MailContainer.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
|
||||
@@ -5,36 +5,12 @@
|
||||
Public Const EMAIL_SUBJECT_TEXT = "<p>Der Betreff der Original-Email war: <em>{0}</em></p>"
|
||||
|
||||
Public Const EMAIL_SUBJECT_REJECTED = "Beleg abgelehnt"
|
||||
Public Const EMAIL_SUBJECT_EXCEPTION = "Unbehandelte Ausnahme"
|
||||
|
||||
Public Const EMAIL_UNHANDLED_EXCEPTION = """
|
||||
<p>Beim Verarbeiten der Datei mit der Message ID '{0}' ist ein schwerer Fehler aufgetreten.</p>
|
||||
<p>Fehlerbeschreibung: {1}</p>
|
||||
<pre>{2}</pre>
|
||||
"""
|
||||
|
||||
Public Const EMAIL_MISSINGPROPERTIES_1 = "<p>Die angehängte Datei entspricht nicht dem ZUGFeRD-Format: {0}</p>"
|
||||
Public Const EMAIL_MISSINGPROPERTIES_2 = "<p>Die folgenden Eigenschaften wurden als ERFORDERLICH eingestuft, wurden aber nicht gefunden:<p/>"
|
||||
|
||||
|
||||
|
||||
Public Const EMAIL_MD5_ERROR = "<p>Die von Ihnen gesendete Rechnung wurde bereits von unserem System verarbeitet.</p>"
|
||||
|
||||
Public Const EMAIL_TOO_MUCH_FERDS = "<p>Ihre Email enthielt mehr als ein ZUGFeRD-Dokument.</p>"
|
||||
|
||||
Public Const EMAIL_NO_FERDS = "<p>Ihre Email enthielt keine Dokumente.</p>"
|
||||
|
||||
Public Const EMAIL_FILE_SIZE_REACHED = "
|
||||
<p>Die von Ihnen gesendete Rechnung oder einer der Rechnungs-Anhänge überschreitet die erlaubte Größe von <strong>{0} MB</strong>.</p>
|
||||
<p>Die folgende Datei hat die erlaubte Größe überschritten:<ul>
|
||||
<li>{1}</li>
|
||||
</ul></p>
|
||||
"
|
||||
|
||||
Public Const EMAIL_INVALID_DOCUMENT = "
|
||||
<p>Ihre Email enthielt ein ZUGFeRD Dokument, welches aber inkorrekt formatiert wurde.</p>
|
||||
<p>Mögliche Gründe für ein inkorrektes Format:<ul>
|
||||
<li>Betrags-Werte weisen ungültiges Format auf (25,01 anstatt 25.01)</li>
|
||||
</ul></p>
|
||||
"
|
||||
''' <summary>
|
||||
''' Präfix für den verwendeten ErrorCode
|
||||
''' Beispiel: EMLP_Rejection_10001
|
||||
''' </summary>
|
||||
Public Const ErrorCodePraefix = "EMLP_Rejection_"
|
||||
End Class
|
||||
|
||||
5
App/EmailProfiler.Common/ErrorCode.vb
Normal file
5
App/EmailProfiler.Common/ErrorCode.vb
Normal file
@@ -0,0 +1,5 @@
|
||||
Public Enum ErrorCode
|
||||
Unknown = 0
|
||||
NoAttachments = 10001
|
||||
SenderValidationFailed = 10002
|
||||
End Enum
|
||||
@@ -41,10 +41,11 @@ Public Class clsWorkEmail
|
||||
Private ReadOnly _Patterns As Patterns2
|
||||
|
||||
Private ReadOnly _EmailAccountID As Integer = 1
|
||||
Private ReadOnly _RejectionTemplateId As Integer = 0
|
||||
|
||||
Private _worked_email As Boolean = False
|
||||
|
||||
Sub New(LogConf As LogConfig, ConStr As String, WmConStr As String, pUseWindream As Boolean, EmailAccountID As Integer, EmlProfPraefix As String)
|
||||
Sub New(LogConf As LogConfig, ConStr As String, WmConStr As String, pUseWindream As Boolean, EmailAccountID As Integer, EmlProfPraefix As String, pRejectionTemplateId As Integer)
|
||||
Try
|
||||
_Logger = LogConf.GetLogger
|
||||
_LogConfig = LogConf
|
||||
@@ -52,6 +53,8 @@ Public Class clsWorkEmail
|
||||
_Logger.Debug("clsWorkmail _email initialized")
|
||||
_UseWindream = pUseWindream
|
||||
_Patterns = New Patterns2(LogConf)
|
||||
_RejectionTemplateId = pRejectionTemplateId
|
||||
_Logger.Debug($"_RejectionTemplateId: {_RejectionTemplateId}")
|
||||
|
||||
If pUseWindream Then
|
||||
_windream = New clsWindream_allgemein(LogConf)
|
||||
@@ -162,7 +165,9 @@ Public Class clsWorkEmail
|
||||
'insert history und exit
|
||||
InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", oResult)
|
||||
|
||||
AddEmailToQueueMSSQL(CurrentMail.MessageId, oResult, "Email validation failed", _EmailAccountID)
|
||||
'AddEmailToQueueMSSQL(CurrentMail.MessageId, oResult, "Email validation failed", _EmailAccountID)
|
||||
AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "Email validation failed", _EmailAccountID,
|
||||
_RejectionTemplateId, ErrorCode.SenderValidationFailed, "", "")
|
||||
|
||||
' Return early from processing eml
|
||||
Return True
|
||||
@@ -186,7 +191,9 @@ Public Class clsWorkEmail
|
||||
If CURRENT_ATTMT_COUNT = 0 Then
|
||||
_Logger.Info("### Mail contained no Attachments!! ###")
|
||||
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
||||
If AddEmailToQueueMSSQL(CurrentMail.MessageId, oBody, "No Attachments", _EmailAccountID) = True Then
|
||||
'If AddEmailToQueueMSSQL(CurrentMail.MessageId, oBody, "No Attachments", _EmailAccountID) = True Then
|
||||
If AddToEmailQueueMSSQL(CurrentMail.MessageId, oBody, "No Attachments", _EmailAccountID,
|
||||
_RejectionTemplateId, ErrorCode.NoAttachments, "", "") = True Then
|
||||
CURRENT_ImapObject.DeleteMessageByUID(poUID)
|
||||
End If
|
||||
InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", "No Attachments")
|
||||
@@ -204,15 +211,136 @@ Public Class clsWorkEmail
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function AddEmailToQueueMSSQL(MessageId As String, BodyText As String, Comment As String, pEmailAccountId As Integer) As Boolean
|
||||
''' <summary>
|
||||
''' Method to decide wether we use the old or the new
|
||||
''' Rejection E-mail method.
|
||||
'''
|
||||
''' TODO we have no information about the language of the receiver at the moment
|
||||
''' </summary>
|
||||
''' <param name="pMessageId">E-Mail Message ID</param>
|
||||
''' <param name="pBodyText">Body Text</param>
|
||||
''' <param name="pComment">Comment</param>
|
||||
''' <param name="pEmailAccountId">Sending Profile from config</param>
|
||||
''' <param name="pTemplateId">ID for E-Mail-Template from config</param>
|
||||
''' <param name="pErrorCode">Error Code</param>
|
||||
''' <param name="pParameter1">Zusätzlicher Parameter 1</param>
|
||||
''' <param name="pParameter2">Zusätzlicher Parameter 2</param>
|
||||
Public Function AddToEmailQueueMSSQL(pMessageId As String, pBodyText As String, pComment As String, pEmailAccountId As Integer,
|
||||
pTemplateId As Integer, pErrorCode As ErrorCode, pParameter1 As String, pParameter2 As String) As Boolean
|
||||
|
||||
Dim useLegacyMethod = True
|
||||
Dim oErrorCode As String = String.Empty
|
||||
|
||||
' ErrorCode valid?
|
||||
If pErrorCode <> ErrorCode.Unknown Then
|
||||
Dim intCode As Integer = DirectCast(pErrorCode, Integer)
|
||||
oErrorCode = $"{EmailStrings.ErrorCodePraefix}{intCode}"
|
||||
|
||||
Dim oSQL = $"SELECT COUNT(*) FROM TBDD_GUI_LANGUAGE_PHRASE WHERE TITLE = '{oErrorCode}'"
|
||||
If _DB_MSSQL.GetScalarValue(oSQL) > 0 Then
|
||||
useLegacyMethod = False
|
||||
Else
|
||||
_Logger.Warn($"Rejection reason [{oErrorCode}] not found in TBDD_GUI_LANGUAGE_PHRASE!")
|
||||
End If
|
||||
End If
|
||||
|
||||
' Gibt es das Template in TBDD_EMAIL_TEMPLATE?
|
||||
If useLegacyMethod = False AndAlso pTemplateId > 0 Then
|
||||
Try
|
||||
Dim oSQL = $"SELECT COUNT(*) FROM TBDD_EMAIL_TEMPLATE WHERE GUID = {pTemplateId}"
|
||||
If _DB_MSSQL.GetScalarValue(oSQL) <= 0 Then
|
||||
_Logger.Warn($"EMAIL_TEMPLATE [{pTemplateId}] not found in TBDD_EMAIL_TEMPLATE!")
|
||||
useLegacyMethod = True
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
useLegacyMethod = True
|
||||
End Try
|
||||
|
||||
Else
|
||||
_Logger.Debug($"RejectionTemplateId not configured!")
|
||||
useLegacyMethod = True
|
||||
End If
|
||||
|
||||
' Check if Stored Procedure PRDD_SEND_REJECTION_MAIL exists
|
||||
If useLegacyMethod = False Then
|
||||
Try
|
||||
Dim oSQL = $"SELECT COUNT(*) FROM sys.objects WHERE type = 'P' AND OBJECT_ID = OBJECT_ID('dbo.PRDD_SEND_REJECTION_MAIL')"
|
||||
If _DB_MSSQL.GetScalarValue(oSQL) <= 0 Then
|
||||
_Logger.Warn($"Procedure ['PRDD_SEND_REJECTION_MAIL'] not found in Database!")
|
||||
useLegacyMethod = True
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
useLegacyMethod = True
|
||||
End Try
|
||||
End If
|
||||
|
||||
If useLegacyMethod = True Then
|
||||
_Logger.Warn("New rejection mail logic is not configured correctly, use legacy logic instead!")
|
||||
Return AddEmailToQueueMSSQL(pMessageId, pBodyText, pComment, pEmailAccountId)
|
||||
Else
|
||||
_Logger.Debug("New rejection mail logic is configured!")
|
||||
Return AddEmailToQueueMSSQL(pMessageId, pTemplateId, oErrorCode, pEmailAccountId, pParameter1, pParameter2)
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Function calls SP PRDD_SEND_REJECTION_MAIL
|
||||
''' for sending rejection mail.
|
||||
''' </summary>
|
||||
''' <param name="pMessageId">E-Mail Message ID</param>
|
||||
''' <param name="pTemplateId">GUID for TBDD_EMAIL_TEMPLATE from config</param>
|
||||
''' <param name="pErrorCode">ErrorID (TBDD_GUI_LANGUAGE_PHRASE)</param>
|
||||
''' <param name="pEmailAccountId">Sending profile from config</param>
|
||||
''' <param name="pParameter1">Zusätzlicher Parameter 1</param>
|
||||
''' <param name="pParameter2">Zusätzlicher Parameter 2</param>
|
||||
Private Function AddEmailToQueueMSSQL(pMessageId As String, pTemplateId As Integer, pErrorCode As String, pEmailAccountId As Integer,
|
||||
pParameter1 As String, pParameter2 As String) As Boolean
|
||||
|
||||
If pParameter1.IsNullOrEmpty Then
|
||||
pParameter1 = ""
|
||||
Else
|
||||
pParameter1 = pParameter1.Replace("'", "''")
|
||||
End If
|
||||
|
||||
If pParameter2.IsNullOrEmpty Then
|
||||
pParameter2 = ""
|
||||
Else
|
||||
pParameter2 = pParameter2.Replace("'", "''")
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oReference = MessageId
|
||||
Dim oExecute = $"EXECUTE dbo.PRDD_SEND_REJECTION_MAIL
|
||||
'{pMessageId}'
|
||||
, 0
|
||||
, {pEmailAccountId}
|
||||
, 'ZUGFeRD Service'
|
||||
, {pTemplateId}
|
||||
, '{pErrorCode}'
|
||||
, '{pParameter1}'
|
||||
, '{pParameter2}'
|
||||
, 77"
|
||||
|
||||
Return _DB_MSSQL.ExecuteNonQuery(oExecute)
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
Public Function AddEmailToQueueMSSQL(pMessageId As String, pBodyText As String, pComment As String, pEmailAccountId As Integer) As Boolean
|
||||
|
||||
Try
|
||||
Dim oReference = pMessageId
|
||||
Dim oEmailTo = ""
|
||||
Dim oSubject = $"{SUBJECT_PRAFIX} - {EmailStrings.EMAIL_SUBJECT_REJECTED}"
|
||||
Dim oCreatedWho = "DDEmailProfiler"
|
||||
|
||||
Dim oMaskedBodyText = BodyText.Replace("'", "''")
|
||||
Dim oMaskedBodyText = pBodyText.Replace("'", "''")
|
||||
Dim oSubjectBodyText = String.Format(EmailStrings.EMAIL_SUBJECT_TEXT, CURRENT_MAIL_SUBJECT)
|
||||
Dim oCompleteBodyText = oMaskedBodyText & oSubjectBodyText
|
||||
|
||||
@@ -222,7 +350,7 @@ Public Class clsWorkEmail
|
||||
|
||||
|
||||
If IsNothing(oEmailAddress) OrElse String.IsNullOrWhiteSpace(oEmailAddress) Then
|
||||
_Logger.Warn("Could not find email-address for MessageId {0}", MessageId)
|
||||
_Logger.Warn("Could not find email-address for MessageId {0}", pMessageId)
|
||||
oEmailTo = String.Empty
|
||||
Else
|
||||
oEmailTo = oEmailAddress
|
||||
@@ -232,7 +360,7 @@ Public Class clsWorkEmail
|
||||
_Logger.Debug("To: {0}", oEmailTo)
|
||||
_Logger.Debug("Subject: {0}", oSubject)
|
||||
_Logger.Debug("Body {0}", oFinalBodyText)
|
||||
Dim osql = $"Select COALESCE(MAX(GUID), 0) FROM TBEMLP_HISTORY WHERE EMAIL_MSGID = '{MessageId}'"
|
||||
Dim osql = $"Select COALESCE(MAX(GUID), 0) FROM TBEMLP_HISTORY WHERE EMAIL_MSGID = '{pMessageId}'"
|
||||
Dim oHistoryID As Integer = _DB_MSSQL.GetScalarValue(osql)
|
||||
|
||||
Dim oInsert = $"INSERT INTO [dbo].[TBEMLP_EMAIL_OUT] (
|
||||
@@ -250,14 +378,14 @@ Public Class clsWorkEmail
|
||||
(77
|
||||
,{pEmailAccountId}
|
||||
,{oHistoryID}
|
||||
,'{MessageId}'
|
||||
,'{pMessageId}'
|
||||
,77
|
||||
,'{oEmailTo}'
|
||||
,'{oSubject}'
|
||||
,'{oFinalBodyText}'
|
||||
,'{Comment}'
|
||||
,'{pComment}'
|
||||
,'{oCreatedWho}')"
|
||||
Return _DB_MSSQL.ExecuteNonQuery(oInsert)
|
||||
Return _DB_MSSQL.ExecuteNonQuery(oInsert)
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
|
||||
@@ -24,7 +24,8 @@ Public Class clsWorker
|
||||
|
||||
Private ReadOnly LocalEmlFile As String = ""
|
||||
|
||||
Sub New(pLogConfig As LogConfig, pConnectionString As String, pWindreamConnectionString As String, pPollProfileId As Integer, pUseWindream As Boolean, pEmailAccountID As Integer, pEmailPrefix As String, pEmailLimitationSender As String, Optional pLocalEML As String = "")
|
||||
Sub New(pLogConfig As LogConfig, pConnectionString As String, pWindreamConnectionString As String, pPollProfileId As Integer, pUseWindream As Boolean,
|
||||
pEmailAccountID As Integer, pEmailPrefix As String, pEmailLimitationSender As String, pRejectionTemplateId As Integer, Optional pLocalEML As String = "")
|
||||
Logger = pLogConfig.GetLogger
|
||||
'ClassEmailImap = New clsEmailIMAP(pLogConfig)
|
||||
Fetcher = New MailFetcher(pLogConfig)
|
||||
@@ -42,7 +43,7 @@ Public Class clsWorker
|
||||
ClassWindreamIndex = New clsWindream_Index(pLogConfig)
|
||||
End If
|
||||
|
||||
ClassWorkMail = New clsWorkEmail(pLogConfig, pConnectionString, pWindreamConnectionString, pUseWindream, pEmailAccountID, pEmailPrefix)
|
||||
ClassWorkMail = New clsWorkEmail(pLogConfig, pConnectionString, pWindreamConnectionString, pUseWindream, pEmailAccountID, pEmailPrefix, pRejectionTemplateId)
|
||||
|
||||
|
||||
Encryption = New clsEncryption("!35452didalog=", pLogConfig)
|
||||
|
||||
Reference in New Issue
Block a user