MS EmailFunctions
- ZuGferd Service - Windream
This commit is contained in:
parent
7abf47c2fc
commit
1d88a8467c
@ -88,7 +88,7 @@ Public Class Form1
|
||||
args = LoadFolderConfig(args)
|
||||
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)
|
||||
End Sub
|
||||
|
||||
@ -62,7 +62,7 @@ Public Class EmailFunctions
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
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
|
||||
_logger.Warn("EmailData is empty. Email will not be sent!")
|
||||
Exit Sub
|
||||
@ -73,7 +73,6 @@ Public Class EmailFunctions
|
||||
Dim oReference = MessageId
|
||||
Dim oEmailTo = ""
|
||||
Dim oSubject = EmailStrings.EMAIL_SUBJECT
|
||||
Dim oAccountId = 1
|
||||
Dim oCreatedWho = "ZUGFeRD Service"
|
||||
Dim oFinalBodyText = String.Format(EmailStrings.EMAIL_WRAPPING_TEXT, BodyText)
|
||||
|
||||
@ -119,7 +118,7 @@ Public Class EmailFunctions
|
||||
,EMAIL_ATTMT1)
|
||||
VALUES
|
||||
(77
|
||||
,{oAccountId}
|
||||
,{pEmailAccountId}
|
||||
,{oHistoryID}
|
||||
,'{MessageId}'
|
||||
,77
|
||||
|
||||
@ -34,15 +34,18 @@ Public Class ImportZUGFeRDFiles
|
||||
Private ReadOnly _zugferd As ZUGFeRDInterface
|
||||
Private ReadOnly _firebird As Firebird
|
||||
Private ReadOnly _filesystem As Filesystem.File
|
||||
Private ReadOnly _EmailOutAccountId As Integer
|
||||
Private ReadOnly _mssql As MSSQLServer
|
||||
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
|
||||
_logger = LogConfig.GetLogger()
|
||||
_firebird = Firebird
|
||||
_filesystem = New Filesystem.File(_logConfig)
|
||||
_mssql = MSSQL
|
||||
_EmailOutAccountId = pEmailOutAccount
|
||||
_email = New EmailFunctions(LogConfig, _mssql, _firebird)
|
||||
|
||||
_logger.Debug("Registering GDPicture License")
|
||||
@ -467,7 +470,7 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Dim oBody = EmailStrings.EMAIL_MD5_ERROR
|
||||
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!", "")
|
||||
Catch ex As InvalidFerdException
|
||||
_logger.Error(ex)
|
||||
@ -477,7 +480,7 @@ Public Class ImportZUGFeRDFiles
|
||||
_firebird.ExecuteNonQuery(oSQL)
|
||||
Dim oBody = EmailStrings.EMAIL_INVALID_DOCUMENT
|
||||
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "InvalidFerdException")
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "InvalidFerdException", _EmailOutAccountId)
|
||||
AddRejectedState(oMessageId, "InvalidFerdException", "Inkorrekte Formate", "")
|
||||
Catch ex As TooMuchFerdsException
|
||||
_logger.Error(ex)
|
||||
@ -487,7 +490,7 @@ Public Class ImportZUGFeRDFiles
|
||||
_firebird.ExecuteNonQuery(oSQL)
|
||||
Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS
|
||||
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", "")
|
||||
Catch ex As NoFerdsException
|
||||
_logger.Error(ex)
|
||||
@ -497,7 +500,7 @@ Public Class ImportZUGFeRDFiles
|
||||
_firebird.ExecuteNonQuery(oSQL)
|
||||
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
||||
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", "")
|
||||
Catch ex As MissingValueException
|
||||
_logger.Error(ex)
|
||||
@ -512,7 +515,7 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
||||
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)
|
||||
|
||||
Catch ex As Exception
|
||||
|
||||
@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices
|
||||
' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
|
||||
<Assembly: AssemblyVersion("1.1.0.2")>
|
||||
<Assembly: AssemblyVersion("1.1.0.3")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
@ -261,6 +261,7 @@ Public Class Email
|
||||
AUTH_TYPE As String, SENDER_INSTANCE As String, Optional attachmentString As String = "", Optional Test As Boolean = False)
|
||||
Dim myClient As Net.Mail.SmtpClient
|
||||
Dim myMesssage As New MailMessage
|
||||
|
||||
Try
|
||||
Dim oError As Boolean = False
|
||||
Dim oReceipiants As String()
|
||||
@ -361,7 +362,7 @@ Public Class Email
|
||||
|
||||
End Function
|
||||
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 = "")
|
||||
Try
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
|
||||
@ -378,16 +379,17 @@ Public Class Email
|
||||
For Each _mailempfaenger As String In empfaenger
|
||||
_logger.Debug($"Working on email for {_mailempfaenger}..")
|
||||
Try
|
||||
Dim message As New Message()
|
||||
message.From = New Mailbox(mailfrom, mailfrom)
|
||||
message.[To].Add(New Mailbox(_mailempfaenger))
|
||||
message.Subject = mailSubject
|
||||
Dim oMessage As New Message()
|
||||
oMessage.From = New Mailbox(from_mailaddress, from_name)
|
||||
|
||||
oMessage.[To].Add(New Mailbox(_mailempfaenger))
|
||||
oMessage.Subject = mailSubject
|
||||
_logger.Debug($"Message created..")
|
||||
Dim textBodyPart As New BodyPart()
|
||||
textBodyPart.ContentType = New ContentType("text", "html", "utf-8")
|
||||
textBodyPart.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable
|
||||
textBodyPart.Body = mailBody
|
||||
message.BodyParts.Add(textBodyPart)
|
||||
oMessage.BodyParts.Add(textBodyPart)
|
||||
If attment <> String.Empty Then
|
||||
If System.IO.File.Exists(attment) Then
|
||||
Dim attachment1 As New Independentsoft.Email.Mime.Attachment(attment)
|
||||
@ -398,7 +400,7 @@ Public Class Email
|
||||
ElseIf attment.ToLower.EndsWith("docx") Then
|
||||
attachment1.ContentType = New ContentType("application", "MS-word")
|
||||
End If
|
||||
message.BodyParts.Add(attachment1)
|
||||
oMessage.BodyParts.Add(attachment1)
|
||||
Else
|
||||
_logger.Warn($"Attachment {attment.ToString} is not existing!")
|
||||
End If
|
||||
@ -469,7 +471,7 @@ Public Class Email
|
||||
End Try
|
||||
End Try
|
||||
Try
|
||||
client.Send(message)
|
||||
client.Send(oMessage)
|
||||
_logger.Info("Message to " & _mailempfaenger & " has been send.")
|
||||
_error = False
|
||||
Catch ex As Exception
|
||||
|
||||
BIN
Modules.Windream/DDWindream.zip
Normal file
BIN
Modules.Windream/DDWindream.zip
Normal file
Binary file not shown.
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.3")>
|
||||
<Assembly: AssemblyVersion("1.0.0.4")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
@ -595,6 +595,7 @@ Public Class Windream
|
||||
|
||||
If TestFolderExists(oCurrentPath) = False Then
|
||||
oFolderObject = Session.GetNewWMObjectFS(WMEntityFolder, oCurrentPath, WMObjectEditModeNoEdit)
|
||||
_logger.Info($"new Folder [{oCurrentPath}] has been created!")
|
||||
End If
|
||||
Next
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ Public Class EmailService
|
||||
Try
|
||||
' === 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
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
|
||||
@ -203,7 +203,7 @@ Public Class EmailService
|
||||
End If
|
||||
|
||||
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
|
||||
|
||||
For Each oEmailToRow As DataRow In oEmailQueue.Rows
|
||||
@ -224,6 +224,7 @@ Public Class EmailService
|
||||
Select Case Database
|
||||
Case DatabaseType.Firebird
|
||||
oMailFrom = oAccountRow.Item("EMAIL_FROM")
|
||||
ofromName = oMailFrom
|
||||
oMailSMTP = oAccountRow.Item("SERVER_OUT")
|
||||
oMailport = oAccountRow.Item("PORT_OUT")
|
||||
oMailUser = oAccountRow.Item("EMAIL_USER")
|
||||
@ -232,6 +233,7 @@ Public Class EmailService
|
||||
|
||||
Case DatabaseType.MSSQL
|
||||
oMailFrom = oAccountRow.Item("EMAIL_FROM")
|
||||
ofromName = oAccountRow.Item("EMAIL_FROM_NAME")
|
||||
oMailSMTP = oAccountRow.Item("EMAIL_SMTP")
|
||||
oMailport = oAccountRow.Item("PORT")
|
||||
oMailUser = oAccountRow.Item("EMAIL_USER")
|
||||
@ -296,7 +298,7 @@ Public Class EmailService
|
||||
End If
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyVersion("1.1.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
<value>10</value>
|
||||
</setting>
|
||||
<setting name="MSSQL_CONNECTIONSTRING" serializeAs="String">
|
||||
<value/>
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="MSSQL_ENABLED" serializeAs="String">
|
||||
<value>False</value>
|
||||
@ -40,6 +40,9 @@
|
||||
<setting name="GDPICTURE_KEY" serializeAs="String">
|
||||
<value>1234567890_EXAMPLE_KEY</value>
|
||||
</setting>
|
||||
<setting name="MSSQLEmailOutAccountID" serializeAs="String">
|
||||
<value>1</value>
|
||||
</setting>
|
||||
</DDZUGFeRDService.My.MySettings>
|
||||
</applicationSettings>
|
||||
<system.data>
|
||||
|
||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.1.0.1")>
|
||||
<Assembly: AssemblyVersion("1.2.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
@ -143,6 +143,15 @@ Namespace My
|
||||
Return CType(Me("GDPICTURE_KEY"),String)
|
||||
End Get
|
||||
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 Namespace
|
||||
|
||||
|
||||
@ -32,5 +32,8 @@
|
||||
<Setting Name="GDPICTURE_KEY" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">1234567890_EXAMPLE_KEY</Value>
|
||||
</Setting>
|
||||
<Setting Name="MSSQLEmailOutAccountID" Type="System.Int32" Scope="Application">
|
||||
<Value Profile="(Default)">1</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@ -112,7 +112,7 @@ Public Class ThreadRunner
|
||||
Dim args As WorkerArgs = e.Argument
|
||||
|
||||
_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)
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Background worker failed!")
|
||||
|
||||
@ -12,7 +12,7 @@ Public Class ZUGFeRDService
|
||||
Private _threadRunner As ThreadRunner
|
||||
|
||||
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
|
||||
_logger = _logConfig.GetLogger()
|
||||
_logger.Info($"{My.Settings.SERVICE_NAME} is starting.")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user