MS EmailFunctions

- ZuGferd Service
- Windream
This commit is contained in:
SchreiberM 2020-04-17 11:55:33 +02:00
parent 7abf47c2fc
commit 1d88a8467c
16 changed files with 50 additions and 28 deletions

View File

@ -88,7 +88,7 @@ Public Class Form1
args = LoadFolderConfig(args) args = LoadFolderConfig(args)
args = LoadPropertyMapFor(args, "DEFAULT") args = LoadPropertyMapFor(args, "DEFAULT")
Dim job As New Jobs.ImportZUGFeRDFiles(_logConfig, _firebird, _mssql) Dim job As New Jobs.ImportZUGFeRDFiles(_logConfig, _firebird, 1, _mssql)
job.Start(args) job.Start(args)
End Sub End Sub

View File

@ -62,7 +62,7 @@ Public Class EmailFunctions
_logger.Error(ex) _logger.Error(ex)
End Try End Try
End Sub End Sub
Public Sub AddToEmailQueueMSSQL(MessageId As String, BodyText As String, pEmailData As EmailData, SourceProcedure As String) Public Sub AddToEmailQueueMSSQL(MessageId As String, BodyText As String, pEmailData As EmailData, SourceProcedure As String, pEmailAccountId As Integer)
If pEmailData Is Nothing Then If pEmailData Is Nothing Then
_logger.Warn("EmailData is empty. Email will not be sent!") _logger.Warn("EmailData is empty. Email will not be sent!")
Exit Sub Exit Sub
@ -73,7 +73,6 @@ Public Class EmailFunctions
Dim oReference = MessageId Dim oReference = MessageId
Dim oEmailTo = "" Dim oEmailTo = ""
Dim oSubject = EmailStrings.EMAIL_SUBJECT Dim oSubject = EmailStrings.EMAIL_SUBJECT
Dim oAccountId = 1
Dim oCreatedWho = "ZUGFeRD Service" Dim oCreatedWho = "ZUGFeRD Service"
Dim oFinalBodyText = String.Format(EmailStrings.EMAIL_WRAPPING_TEXT, BodyText) Dim oFinalBodyText = String.Format(EmailStrings.EMAIL_WRAPPING_TEXT, BodyText)
@ -119,7 +118,7 @@ Public Class EmailFunctions
,EMAIL_ATTMT1) ,EMAIL_ATTMT1)
VALUES VALUES
(77 (77
,{oAccountId} ,{pEmailAccountId}
,{oHistoryID} ,{oHistoryID}
,'{MessageId}' ,'{MessageId}'
,77 ,77

View File

@ -34,15 +34,18 @@ Public Class ImportZUGFeRDFiles
Private ReadOnly _zugferd As ZUGFeRDInterface Private ReadOnly _zugferd As ZUGFeRDInterface
Private ReadOnly _firebird As Firebird Private ReadOnly _firebird As Firebird
Private ReadOnly _filesystem As Filesystem.File Private ReadOnly _filesystem As Filesystem.File
Private ReadOnly _EmailOutAccountId As Integer
Private ReadOnly _mssql As MSSQLServer Private ReadOnly _mssql As MSSQLServer
Private ReadOnly _email As EmailFunctions Private ReadOnly _email As EmailFunctions
Public Sub New(LogConfig As LogConfig, Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing)
Public Sub New(LogConfig As LogConfig, Firebird As Firebird, pEmailOutAccount As Integer, Optional MSSQL As MSSQLServer = Nothing)
_logConfig = LogConfig _logConfig = LogConfig
_logger = LogConfig.GetLogger() _logger = LogConfig.GetLogger()
_firebird = Firebird _firebird = Firebird
_filesystem = New Filesystem.File(_logConfig) _filesystem = New Filesystem.File(_logConfig)
_mssql = MSSQL _mssql = MSSQL
_EmailOutAccountId = pEmailOutAccount
_email = New EmailFunctions(LogConfig, _mssql, _firebird) _email = New EmailFunctions(LogConfig, _mssql, _firebird)
_logger.Debug("Registering GDPicture License") _logger.Debug("Registering GDPicture License")
@ -467,7 +470,7 @@ Public Class ImportZUGFeRDFiles
Dim oBody = EmailStrings.EMAIL_MD5_ERROR Dim oBody = EmailStrings.EMAIL_MD5_ERROR
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId) Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "MD5HashException") _email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "MD5HashException", _EmailOutAccountId)
AddRejectedState(oMessageId, "MD5HashException", "Die gesendete Rechnung wurde bereits verarbeitet!", "") AddRejectedState(oMessageId, "MD5HashException", "Die gesendete Rechnung wurde bereits verarbeitet!", "")
Catch ex As InvalidFerdException Catch ex As InvalidFerdException
_logger.Error(ex) _logger.Error(ex)
@ -477,7 +480,7 @@ Public Class ImportZUGFeRDFiles
_firebird.ExecuteNonQuery(oSQL) _firebird.ExecuteNonQuery(oSQL)
Dim oBody = EmailStrings.EMAIL_INVALID_DOCUMENT Dim oBody = EmailStrings.EMAIL_INVALID_DOCUMENT
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId) Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "InvalidFerdException") _email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "InvalidFerdException", _EmailOutAccountId)
AddRejectedState(oMessageId, "InvalidFerdException", "Inkorrekte Formate", "") AddRejectedState(oMessageId, "InvalidFerdException", "Inkorrekte Formate", "")
Catch ex As TooMuchFerdsException Catch ex As TooMuchFerdsException
_logger.Error(ex) _logger.Error(ex)
@ -487,7 +490,7 @@ Public Class ImportZUGFeRDFiles
_firebird.ExecuteNonQuery(oSQL) _firebird.ExecuteNonQuery(oSQL)
Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId) Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "TooMuchFerdsException") _email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "TooMuchFerdsException", _EmailOutAccountId)
AddRejectedState(oMessageId, "TooMuchFerdsException", "Email enthielt mehr als ein ZUGFeRD-Dokument", "") AddRejectedState(oMessageId, "TooMuchFerdsException", "Email enthielt mehr als ein ZUGFeRD-Dokument", "")
Catch ex As NoFerdsException Catch ex As NoFerdsException
_logger.Error(ex) _logger.Error(ex)
@ -497,7 +500,7 @@ Public Class ImportZUGFeRDFiles
_firebird.ExecuteNonQuery(oSQL) _firebird.ExecuteNonQuery(oSQL)
Dim oBody = EmailStrings.EMAIL_NO_FERDS Dim oBody = EmailStrings.EMAIL_NO_FERDS
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId) Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "NoFerdsException") _email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "NoFerdsException", _EmailOutAccountId)
AddRejectedState(oMessageId, "NoFerdsException", " Email enthielt keine ZUGFeRD-Dokumente", "") AddRejectedState(oMessageId, "NoFerdsException", " Email enthielt keine ZUGFeRD-Dokumente", "")
Catch ex As MissingValueException Catch ex As MissingValueException
_logger.Error(ex) _logger.Error(ex)
@ -512,7 +515,7 @@ Public Class ImportZUGFeRDFiles
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties) Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId) Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "MissingValueException") _email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "MissingValueException", _EmailOutAccountId)
AddRejectedState(oMessageId, "MissingValueException", "Es fehlten ZugferdSpezifikationen", oMessage) AddRejectedState(oMessageId, "MissingValueException", "Es fehlten ZugferdSpezifikationen", oMessage)
Catch ex As Exception Catch ex As Exception

View File

@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices
' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern ' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
<Assembly: AssemblyVersion("1.1.0.2")> <Assembly: AssemblyVersion("1.1.0.3")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@ -261,6 +261,7 @@ Public Class Email
AUTH_TYPE As String, SENDER_INSTANCE As String, Optional attachmentString As String = "", Optional Test As Boolean = False) AUTH_TYPE As String, SENDER_INSTANCE As String, Optional attachmentString As String = "", Optional Test As Boolean = False)
Dim myClient As Net.Mail.SmtpClient Dim myClient As Net.Mail.SmtpClient
Dim myMesssage As New MailMessage Dim myMesssage As New MailMessage
Try Try
Dim oError As Boolean = False Dim oError As Boolean = False
Dim oReceipiants As String() Dim oReceipiants As String()
@ -361,7 +362,7 @@ Public Class Email
End Function End Function
Public Function New_EmailISoft(ByVal mailSubject As String, ByVal mailBody As String, mailto As String, Public Function New_EmailISoft(ByVal mailSubject As String, ByVal mailBody As String, mailto As String,
mailfrom As String, mailsmtp As String, mailport As Integer, mailUser As String, mailPW As String, from_mailaddress As String, from_name As String, mailsmtp As String, mailport As Integer, mailUser As String, mailPW As String,
AUTH_TYPE As String, SENDER_INSTANCE As String, Optional attment As String = "") AUTH_TYPE As String, SENDER_INSTANCE As String, Optional attment As String = "")
Try Try
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
@ -378,16 +379,17 @@ Public Class Email
For Each _mailempfaenger As String In empfaenger For Each _mailempfaenger As String In empfaenger
_logger.Debug($"Working on email for {_mailempfaenger}..") _logger.Debug($"Working on email for {_mailempfaenger}..")
Try Try
Dim message As New Message() Dim oMessage As New Message()
message.From = New Mailbox(mailfrom, mailfrom) oMessage.From = New Mailbox(from_mailaddress, from_name)
message.[To].Add(New Mailbox(_mailempfaenger))
message.Subject = mailSubject oMessage.[To].Add(New Mailbox(_mailempfaenger))
oMessage.Subject = mailSubject
_logger.Debug($"Message created..") _logger.Debug($"Message created..")
Dim textBodyPart As New BodyPart() Dim textBodyPart As New BodyPart()
textBodyPart.ContentType = New ContentType("text", "html", "utf-8") textBodyPart.ContentType = New ContentType("text", "html", "utf-8")
textBodyPart.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable textBodyPart.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable
textBodyPart.Body = mailBody textBodyPart.Body = mailBody
message.BodyParts.Add(textBodyPart) oMessage.BodyParts.Add(textBodyPart)
If attment <> String.Empty Then If attment <> String.Empty Then
If System.IO.File.Exists(attment) Then If System.IO.File.Exists(attment) Then
Dim attachment1 As New Independentsoft.Email.Mime.Attachment(attment) Dim attachment1 As New Independentsoft.Email.Mime.Attachment(attment)
@ -398,7 +400,7 @@ Public Class Email
ElseIf attment.ToLower.EndsWith("docx") Then ElseIf attment.ToLower.EndsWith("docx") Then
attachment1.ContentType = New ContentType("application", "MS-word") attachment1.ContentType = New ContentType("application", "MS-word")
End If End If
message.BodyParts.Add(attachment1) oMessage.BodyParts.Add(attachment1)
Else Else
_logger.Warn($"Attachment {attment.ToString} is not existing!") _logger.Warn($"Attachment {attment.ToString} is not existing!")
End If End If
@ -469,7 +471,7 @@ Public Class Email
End Try End Try
End Try End Try
Try Try
client.Send(message) client.Send(oMessage)
_logger.Info("Message to " & _mailempfaenger & " has been send.") _logger.Info("Message to " & _mailempfaenger & " has been send.")
_error = False _error = False
Catch ex As Exception Catch ex As Exception

Binary file not shown.

View File

@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.3")> <Assembly: AssemblyVersion("1.0.0.4")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@ -595,6 +595,7 @@ Public Class Windream
If TestFolderExists(oCurrentPath) = False Then If TestFolderExists(oCurrentPath) = False Then
oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oCurrentPath, WMObjectEditModeNoEdit) oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oCurrentPath, WMObjectEditModeNoEdit)
_logger.Info($"new Folder [{oCurrentPath}] has been created!")
End If End If
Next Next

View File

@ -29,7 +29,7 @@ Public Class EmailService
Try Try
' === Initialize Logger === ' === Initialize Logger ===
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log")) _LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "EmailService")
_LogConfig.Debug = My.Settings.DEBUG _LogConfig.Debug = My.Settings.DEBUG
_Logger = _LogConfig.GetLogger() _Logger = _LogConfig.GetLogger()
@ -203,7 +203,7 @@ Public Class EmailService
End If End If
Dim oEmailTo, oSubject, oBody As String Dim oEmailTo, oSubject, oBody As String
Dim oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment Dim oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment, ofromName
Dim oAccountId, oGuid, oJobId As Integer Dim oAccountId, oGuid, oJobId As Integer
For Each oEmailToRow As DataRow In oEmailQueue.Rows For Each oEmailToRow As DataRow In oEmailQueue.Rows
@ -224,6 +224,7 @@ Public Class EmailService
Select Case Database Select Case Database
Case DatabaseType.Firebird Case DatabaseType.Firebird
oMailFrom = oAccountRow.Item("EMAIL_FROM") oMailFrom = oAccountRow.Item("EMAIL_FROM")
ofromName = oMailFrom
oMailSMTP = oAccountRow.Item("SERVER_OUT") oMailSMTP = oAccountRow.Item("SERVER_OUT")
oMailport = oAccountRow.Item("PORT_OUT") oMailport = oAccountRow.Item("PORT_OUT")
oMailUser = oAccountRow.Item("EMAIL_USER") oMailUser = oAccountRow.Item("EMAIL_USER")
@ -232,6 +233,7 @@ Public Class EmailService
Case DatabaseType.MSSQL Case DatabaseType.MSSQL
oMailFrom = oAccountRow.Item("EMAIL_FROM") oMailFrom = oAccountRow.Item("EMAIL_FROM")
ofromName = oAccountRow.Item("EMAIL_FROM_NAME")
oMailSMTP = oAccountRow.Item("EMAIL_SMTP") oMailSMTP = oAccountRow.Item("EMAIL_SMTP")
oMailport = oAccountRow.Item("PORT") oMailport = oAccountRow.Item("PORT")
oMailUser = oAccountRow.Item("EMAIL_USER") oMailUser = oAccountRow.Item("EMAIL_USER")
@ -296,7 +298,7 @@ Public Class EmailService
End If End If
Dim oEmailSent As Boolean = False Dim oEmailSent As Boolean = False
oEmailSent = _Email.New_EmailISoft(oSubject, oBody, oEmailTo, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, "DDEmailService", oAttachment) oEmailSent = _Email.New_EmailISoft(oSubject, oBody, oEmailTo, oMailFrom, ofromName, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, "DDEmailService", oAttachment)
If oEmailSent Then If oEmailSent Then

View File

@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")> <Assembly: AssemblyVersion("1.1.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@ -32,7 +32,7 @@
<value>10</value> <value>10</value>
</setting> </setting>
<setting name="MSSQL_CONNECTIONSTRING" serializeAs="String"> <setting name="MSSQL_CONNECTIONSTRING" serializeAs="String">
<value/> <value />
</setting> </setting>
<setting name="MSSQL_ENABLED" serializeAs="String"> <setting name="MSSQL_ENABLED" serializeAs="String">
<value>False</value> <value>False</value>
@ -40,6 +40,9 @@
<setting name="GDPICTURE_KEY" serializeAs="String"> <setting name="GDPICTURE_KEY" serializeAs="String">
<value>1234567890_EXAMPLE_KEY</value> <value>1234567890_EXAMPLE_KEY</value>
</setting> </setting>
<setting name="MSSQLEmailOutAccountID" serializeAs="String">
<value>1</value>
</setting>
</DDZUGFeRDService.My.MySettings> </DDZUGFeRDService.My.MySettings>
</applicationSettings> </applicationSettings>
<system.data> <system.data>

View File

@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.1.0.1")> <Assembly: AssemblyVersion("1.2.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@ -143,6 +143,15 @@ Namespace My
Return CType(Me("GDPICTURE_KEY"),String) Return CType(Me("GDPICTURE_KEY"),String)
End Get End Get
End Property End Property
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("1")> _
Public ReadOnly Property MSSQLEmailOutAccountID() As Integer
Get
Return CType(Me("MSSQLEmailOutAccountID"),Integer)
End Get
End Property
End Class End Class
End Namespace End Namespace

View File

@ -32,5 +32,8 @@
<Setting Name="GDPICTURE_KEY" Type="System.String" Scope="Application"> <Setting Name="GDPICTURE_KEY" Type="System.String" Scope="Application">
<Value Profile="(Default)">1234567890_EXAMPLE_KEY</Value> <Value Profile="(Default)">1234567890_EXAMPLE_KEY</Value>
</Setting> </Setting>
<Setting Name="MSSQLEmailOutAccountID" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">1</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@ -112,7 +112,7 @@ Public Class ThreadRunner
Dim args As WorkerArgs = e.Argument Dim args As WorkerArgs = e.Argument
_logger.Debug("Background worker running..") _logger.Debug("Background worker running..")
Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, _mssql) Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, My.Settings.MSSQLEmailOutAccountID, _mssql)
job.Start(args) job.Start(args)
Catch ex As Exception Catch ex As Exception
_logger.Warn("Background worker failed!") _logger.Warn("Background worker failed!")

View File

@ -12,7 +12,7 @@ Public Class ZUGFeRDService
Private _threadRunner As ThreadRunner Private _threadRunner As ThreadRunner
Protected Overrides Sub OnStart(ByVal args() As String) Protected Overrides Sub OnStart(ByVal args() As String)
_logConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log")) _logConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "DDZUGFeRDService")
_logConfig.Debug = True _logConfig.Debug = True
_logger = _logConfig.GetLogger() _logger = _logConfig.GetLogger()
_logger.Info($"{My.Settings.SERVICE_NAME} is starting.") _logger.Info($"{My.Settings.SERVICE_NAME} is starting.")