This commit is contained in:
Jonathan Jenne 2019-05-10 17:20:03 +02:00
commit 6650b01b10
6 changed files with 271 additions and 87 deletions

View File

@ -25,6 +25,9 @@
<setting name="LOG_ERRORS_ONLY" serializeAs="String">
<value>True</value>
</setting>
<setting name="SQLSERVER_CS" serializeAs="String">
<value>Data Source=172.24.12.41\Tests;Initial Catalog=DD_ECM_TEST;Persist Security Info=True;User ID=sa;Password=dd</value>
</setting>
</DD_CommunicationService.My.MySettings>
</applicationSettings>
</configuration>

View File

@ -47,6 +47,9 @@
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="DigitalData.EMLProfiler">
<HintPath>..\..\DD_EmailProfiler\App\DigitalData.EMLProfiler\bin\Debug\DigitalData.EMLProfiler.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Database">
<HintPath>..\Modules.Database\bin\Debug\DigitalData.Modules.Database.dll</HintPath>
</Reference>

View File

@ -98,6 +98,16 @@ Namespace My
Return CType(Me("LOG_ERRORS_ONLY"),Boolean)
End Get
End Property
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("Data Source=172.24.12.41\Tests;Initial Catalog=DD_ECM_TEST;Persist Security Info="& _
"True;User ID=sa;Password=dd")> _
Public ReadOnly Property SQLSERVER_CS() As String
Get
Return CType(Me("SQLSERVER_CS"),String)
End Get
End Property
End Class
End Namespace

View File

@ -17,5 +17,8 @@
<Setting Name="LOG_ERRORS_ONLY" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="SQLSERVER_CS" Type="System.String" Scope="Application">
<Value Profile="(Default)">Data Source=172.24.12.41\Tests;Initial Catalog=DD_ECM_TEST;Persist Security Info=True;User ID=sa;Password=dd</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -2,27 +2,32 @@
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Messaging
Imports DigitalData.EMLProfiler
Imports System.IO
Public Class MyComService
Private _Logger As Logger
Private _MyLogger As LogConfig
Private myLogger As Logger
Private MyLoConfig As LogConfig
Private _firebird As Firebird
Private _MSSQL As MSSQLServer
Private _Email As Email
Private _EmailAlt As clsEmail
Public Shared threadEmailQueue As BackgroundWorker
Protected Overrides Sub OnStart(ByVal args() As String)
' Code zum Starten des Dienstes hier einfügen. Diese Methode sollte Vorgänge
' ausführen, damit der Dienst gestartet werden kann.
Try
_MyLogger = New LogConfig(LogConfig.PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"))
MyLoConfig = New LogConfig(LogConfig.PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"))
If My.Settings.LOG_ERRORS_ONLY = False Then
_MyLogger.Debug = True
MyLoConfig.Debug = True
Else
_MyLogger.Debug = False
MyLoConfig.Debug = False
End If
_Logger = _MyLogger.GetLogger()
_firebird = New Firebird(_MyLogger, My.Settings.FB_ConnString, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PW)
_Email = New Email(_MyLogger)
myLogger = MyLoConfig.GetLogger()
_firebird = New Firebird(MyLoConfig, My.Settings.FB_ConnString, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PW)
_Email = New Email(MyLoConfig)
_EmailAlt = New clsEmail(MyLoConfig)
_MSSQL = New MSSQLServer(MyLoConfig, My.Settings.SQLSERVER_CS)
If _firebird._DBInitialized = True Then
MyComService.threadEmailQueue = New BackgroundWorker()
MyComService.threadEmailQueue.WorkerReportsProgress = True
@ -41,11 +46,11 @@ Public Class MyComService
'ClassLogger.Add("Timer - Intervall: " & clsSQLITE.konf_intervall & " Minuten", False)
Timer1_OneMinute.Enabled = True
_Logger.Debug("Timer1_OneMinute started...")
myLogger.Debug("Timer1_OneMinute started...")
End If
Catch ex As Exception
If Not IsNothing(_MyLogger.LogFile) And File.Exists(_MyLogger.LogFile) Then
_Logger.Error(ex)
If Not IsNothing(MyLoConfig.LogFile) And File.Exists(MyLoConfig.LogFile) Then
myLogger.Error(ex)
End If
End Try
End Sub
@ -57,51 +62,61 @@ Public Class MyComService
Protected Overrides Sub OnStop()
Try
' Hier Code zum Ausführen erforderlicher Löschvorgänge zum Beenden des Dienstes einfügen.
_Logger.Warn("Service has been stopped!")
myLogger.Warn("Service has been stopped!")
Catch ex As Exception
_Logger.Error(ex)
myLogger.Error(ex)
End Try
End Sub
Public Sub RunThread_EmailQueue(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Try
_MyLogger = New LogConfig(LogConfig.PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"))
_Logger = _MyLogger.GetLogger()
MyLoConfig = New LogConfig(LogConfig.PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"))
myLogger = MyLoConfig.GetLogger()
If My.Settings.LOG_ERRORS_ONLY = False Then
_MyLogger.Debug = True
MyLoConfig.Debug = True
Else
_MyLogger.Debug = False
MyLoConfig.Debug = False
End If
_Email = New Email(_MyLogger)
_firebird = New Firebird(_MyLogger, My.Settings.FB_ConnString, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PW)
_Email = New Email(MyLoConfig)
_firebird = New Firebird(MyLoConfig, My.Settings.FB_ConnString, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PW)
If _firebird._DBInitialized = False Then
_Logger.Warn("Firebird-DB could not be intitialized!")
myLogger.Warn("Firebird-DB could not be intitialized!")
Exit Sub
End If
SEND_FROM_FBDB()
SEND_FROM_MSSQL()
Catch ex As Exception
myLogger.Error(ex)
End Try
End Sub
Private Function SEND_FROM_FBDB()
Try
Dim oComment As String
Dim oSQL = "SELECT * FROM TBEDM_EMAIL_ACCOUNT WHERE ACTIVE = True"
Dim oDT_EMAIL_ACCOUNT As DataTable = _firebird.GetDatatable(oSQL)
If IsNothing(oDT_EMAIL_ACCOUNT) Then
_Logger.Warn("DT_EMAIL_ACCOUNT is nothing!")
Exit Sub
myLogger.Warn("DT_EMAIL_ACCOUNT is nothing!")
Return False
End If
oSQL = "SELECT * FROM TBEDM_EMAIL_QUEUE WHERE EMAIL_SENT IS NULL and EMAIL_TO <> ''"
Dim oDT_EMAIL_QUEUE As DataTable = _firebird.GetDatatable(oSQL)
If Not IsNothing(oDT_EMAIL_QUEUE) And oDT_EMAIL_ACCOUNT.Rows.Count >= 1 Then
Dim oEmailTo, oSubject, oBody As String
Dim oEMAILACCOUNT_ID, oGUID, oJOB_ID As Integer
For Each oEmail_Row As DataRow In oDT_EMAIL_QUEUE.Rows
oEMAILACCOUNT_ID = oEmail_Row.Item("EMAIL_ACCOUNT_ID")
Dim oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment As String
For Each oNewEmailTo_Row As DataRow In oDT_EMAIL_QUEUE.Rows
oEMAILACCOUNT_ID = oNewEmailTo_Row.Item("EMAIL_ACCOUNT_ID")
Dim oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment
Dim oACCOUNT_MATCH As Boolean = False
For Each oAccountRow As DataRow In oDT_EMAIL_ACCOUNT.Rows
If oAccountRow.Item("GUID") = oEMAILACCOUNT_ID Then
For Each oEmailAccountRow As DataRow In oDT_EMAIL_ACCOUNT.Rows
If oEmailAccountRow.Item("GUID") = oEMAILACCOUNT_ID Then
oACCOUNT_MATCH = True
oMailFrom = oAccountRow.Item("EMAIL_FROM")
oMailSMTP = oAccountRow.Item("SERVER_OUT")
oMailport = oAccountRow.Item("PORT_OUT")
oMailUser = oAccountRow.Item("EMAIL_USER")
oAuthType = oAccountRow.Item("AUTH_TYPE")
oMailPW = oAccountRow.Item("EMAIL_PW")
oMailFrom = oEmailAccountRow.Item("EMAIL_FROM")
oMailSMTP = oEmailAccountRow.Item("SERVER_OUT")
oMailport = oEmailAccountRow.Item("PORT_OUT")
oMailUser = oEmailAccountRow.Item("EMAIL_USER")
oAuthType = oEmailAccountRow.Item("AUTH_TYPE")
oMailPW = oEmailAccountRow.Item("EMAIL_PW")
Dim owrapper As New clsEncryption("!35452didalog=")
@ -109,79 +124,212 @@ Public Class MyComService
If Not IsNothing(oPWPlain) Then
oMailPW = oPWPlain
Else
_Logger.Warn("PWPlain is Nothing - Could not decrypt password..")
Exit Sub
myLogger.Warn("PWPlain is Nothing - Could not decrypt password..")
Return False
End If
End If
Next
If IsNothing(oMailFrom) Or IsNothing(oMailPW) Then
If oACCOUNT_MATCH = True Then
_Logger.Warn("ACCOUNT-Infos are nothing!")
myLogger.Warn("ACCOUNT-Infos are nothing!")
Else
_Logger.Warn($"EMAIL_ACCOUNT_ID {oEMAILACCOUNT_ID} is not matching the configuration!")
myLogger.Warn($"EMAIL_ACCOUNT_ID {oEMAILACCOUNT_ID} is not matching the configuration!")
End If
Exit Sub
Return False
End If
oGUID = oEmail_Row.Item("GUID")
oEmailTo = oEmail_Row.Item("EMAIL_TO")
oSubject = oEmail_Row.Item("EMAIL_SUBJ")
oBody = oEmail_Row.Item("EMAIL_BODY")
oJOB_ID = oEmail_Row.Item("JOB_ID")
oGUID = oNewEmailTo_Row.Item("GUID")
oEmailTo = oNewEmailTo_Row.Item("EMAIL_TO")
myLogger.Debug($"oEmailTo: {oEmailTo}")
oSubject = oNewEmailTo_Row.Item("EMAIL_SUBJ")
myLogger.Debug($"oSubject: {oSubject}")
oBody = oNewEmailTo_Row.Item("EMAIL_BODY")
myLogger.Debug($"oBody: {oBody}")
oJOB_ID = oNewEmailTo_Row.Item("JOB_ID")
myLogger.Debug($"oJOB_ID: {oJOB_ID}")
oAttachment = oNewEmailTo_Row.Item("EMAIL_ATTMT1")
If IsNothing(oEmail_Row.Item("EMAIL_ATTMT1")) Then
myLogger.Debug($"Now checking the attachment")
If IsDBNull(oAttachment) Then
oAttachment = String.Empty
Else
oAttachment = oEmail_Row.Item("EMAIL_ATTMT1")
If oAttachment <> String.Empty Then
If File.Exists(oAttachment) = False Then
_Logger.Warn($"Email Attachment FileNotFound Exception!")
Exit Sub
myLogger.Warn($"Email Attachment FB FileNotFound Exception!")
oComment = "Email Attachment FB FileNotFound Exception"
oAttachment = String.Empty
Else
_Logger.Info("Email Attachment is: {0}", oAttachment.ToString)
myLogger.Debug("Email Attachment is: {0}", oAttachment.ToString)
End If
End If
Dim link As String = "pmo://" & oJOB_ID & "-" & oEmail_Row.Item("REFERENCE1")
If oBody.Contains("[%PMOLINK_GER]") Then
oBody = oBody.Replace("[%PMOLINK_GER]", "<a href=""" & link & """>hier</a>")
End If
If oBody.Contains("[%PMOLINK_EN]") Or oBody.Contains("[%PMOLINK_US]") Then
oBody = oBody.Replace("[%PMOLINK_EN]", "<a href=""" & link & """>here</a>")
oBody = oBody.Replace("[%PMOLINK_US]", "<a href=""" & link & """>here</a>")
End If
If _Email.NewEmail(oEmailTo, oSubject, oBody, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, "DDEDMI_ComService", oAttachment.ToString) = True Then
Dim upd = "UPDATE TBEDM_EMAIL_QUEUE SET EMAIL_SENT = CURRENT_TIMESTAMP WHERE GUID = " & oGUID
End If
'Dim link As String = "pmo://" & oJOB_ID & "-" & oNewEmailTo_Row.Item("REFERENCE1")
'If oBody.Contains("[%PMOLINK_GER]") Then
' oBody = oBody.Replace("[%PMOLINK_GER]", "<a href=""" & link & """>hier</a>")
'End If
'If oBody.Contains("[%PMOLINK_EN]") Or oBody.Contains("[%PMOLINK_US]") Then
' oBody = oBody.Replace("[%PMOLINK_EN]", "<a href=""" & link & """>here</a>")
' oBody = oBody.Replace("[%PMOLINK_US]", "<a href=""" & link & """>here</a>")
'End If
Dim oSendResult As Boolean = False
oSendResult = _EmailAlt.Email_Send_Independentsoft(oSubject, oBody, oEmailTo, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment)
If oSendResult = False Then
oSendResult = _Email.NewEmail(oEmailTo, oSubject, oBody, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, "DDEDMI_ComService", oAttachment.ToString)
End If
If oSendResult = True Then
Dim upd = $"UPDATE TBEDM_EMAIL_QUEUE SET EMAIL_SENT = CURRENT_TIMESTAMP,COMMENT = '{oComment}' WHERE GUID = {oGUID}"
If upd.Contains(",COMMENT = ''") Then
upd.Replace(",COMMENT = ''", "")
End If
_firebird.ExecuteNonQuery(upd)
End If
Next
Return True
Else
If oDT_EMAIL_ACCOUNT.Rows.Count = 0 Then
_Logger.Warn("Check the Email_Config Table TBEDM_EMAIL_ACCOUNT. The table seems to be empty.")
myLogger.Warn("Check the Email_Config Table TBDD_EMAIL_ACCOUNT. The table seems to be empty.")
ElseIf IsNothing(oDT_EMAIL_QUEUE) Then
_Logger.Warn($"DT_EMAIL_QUEUE is nothing: {oSQL}")
myLogger.Warn($"DT_EMAIL_QUEUE is nothing: {oSQL}")
End If
End If
Catch ex As Exception
_Logger.Error(ex)
myLogger.Error(ex)
End Try
End Sub
End Function
Private Function SEND_FROM_MSSQL()
Try
If _MSSQL.DBInitialized = False Then
Return False
End If
Dim oSQL = "SELECT * FROM TBDD_EMAIL_ACCOUNT WHERE ACTIVE = 1"
Dim oDT_EMAIL_ACCOUNT As DataTable = _MSSQL.GetDatatable(oSQL)
If IsNothing(oDT_EMAIL_ACCOUNT) Then
myLogger.Warn("DT_EMAIL_ACCOUNT is nothing!")
Return False
End If
oSQL = "SELECT * FROM TBEMLP_EMAIL_OUT WHERE EMAIL_SENT IS NULL and EMAIL_ADRESS <> ''"
Dim oDT_EMAIL_QUEUE As DataTable = _MSSQL.GetDatatable(oSQL)
If Not IsNothing(oDT_EMAIL_QUEUE) And oDT_EMAIL_ACCOUNT.Rows.Count >= 1 Then
Dim oEmailTo, oSubject, oBody As String
Dim oEMAILACCOUNT_ID, oGUID, oJOB_ID As Integer
For Each oEmail_Row As DataRow In oDT_EMAIL_QUEUE.Rows
oEMAILACCOUNT_ID = oEmail_Row.Item("SENDING_PROFILE")
Dim oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment
Dim oACCOUNT_MATCH As Boolean = False
For Each oAccountRow As DataRow In oDT_EMAIL_ACCOUNT.Rows
If oAccountRow.Item("GUID") = oEMAILACCOUNT_ID Then
oACCOUNT_MATCH = True
oMailFrom = oAccountRow.Item("EMAIL_FROM")
oMailSMTP = oAccountRow.Item("EMAIL_SMTP")
oMailport = oAccountRow.Item("PORT")
oMailUser = oAccountRow.Item("EMAIL_USER")
oAuthType = oAccountRow.Item("AUTH_TYPE")
oMailPW = oAccountRow.Item("EMAIL_PW")
Dim owrapper As New clsEncryption("!35452didalog=")
Dim oPWPlain = owrapper.DecryptData(oMailPW)
If Not IsNothing(oPWPlain) Then
oMailPW = oPWPlain
Else
myLogger.Warn("PWPlain is Nothing - Could not decrypt password..")
Return False
End If
End If
Next
If IsNothing(oMailFrom) Or IsNothing(oMailPW) Then
If oACCOUNT_MATCH = True Then
myLogger.Warn("ACCOUNT-Infos are nothing!")
Else
myLogger.Warn($"EMAIL_ACCOUNT_ID {oEMAILACCOUNT_ID} is not matching the configuration!")
End If
Return False
End If
oGUID = oEmail_Row.Item("GUID")
oEmailTo = oEmail_Row.Item("EMAIL_ADRESS")
myLogger.Debug($"oEmailTo: {oEmailTo}")
oSubject = oEmail_Row.Item("EMAIL_SUBJ")
myLogger.Debug($"oSubject: {oSubject}")
oBody = oEmail_Row.Item("EMAIL_BODY")
myLogger.Debug($"oBody: {oBody}")
oJOB_ID = oEmail_Row.Item("REFERENCE_ID")
myLogger.Debug($"oJOB_ID: {oJOB_ID}")
oAttachment = oEmail_Row.Item("EMAIL_ATTMT1")
Try
myLogger.Debug($"Now checking the attachment")
If IsDBNull(oAttachment) Then
oAttachment = String.Empty
Else
If oAttachment <> String.Empty Then
If File.Exists(oAttachment) = False Then
myLogger.Warn($"Email Attachment MSSQL FileNotFound Exception!")
oAttachment = String.Empty
Else
myLogger.Debug("Email Attachment is: {0}", oAttachment.ToString)
End If
End If
End If
Catch ex As Exception
oAttachment = String.Empty
End Try
Dim oSendResult As Boolean = False
oSendResult = _EmailAlt.Email_Send_Independentsoft(oSubject, oBody, oEmailTo, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oAttachment)
If oSendResult = False Then
oSendResult = _Email.NewEmail(oEmailTo, oSubject, oBody, oMailFrom, oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, "DDEDMI_ComService", oAttachment.ToString)
End If
If oSendResult = True Then
Dim oUpdCommand = "UPDATE TBEMLP_EMAIL_OUT SET EMAIL_SENT = GETDATE() WHERE GUID = " & oGUID
_MSSQL.NewExecutenonQuery(oUpdCommand)
End If
Next
Else
If oDT_EMAIL_ACCOUNT.Rows.Count = 0 Then
myLogger.Warn("Check the Email_Config Table TBEDM_EMAIL_ACCOUNT. The table seems to be empty.")
ElseIf IsNothing(oDT_EMAIL_QUEUE) Then
myLogger.Warn($"DT_EMAIL_QUEUE is nothing: {oSQL}")
End If
End If
Catch ex As Exception
myLogger.Error(ex)
End Try
End Function
#Region "*** BackgroundWorker Stop/Completed ***"
Private Sub ThreadEMailQueue_Completed(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) 'Handles threadDateiimport.RunWorkerCompleted
' This event fires when the DoWork event completes
Try
Dim result As String = ""
If e.Cancelled Then
_Logger.Warn("ThreadEMailQueue has been cancelled manually...")
myLogger.Warn("ThreadEMailQueue has been cancelled manually...")
ElseIf e.Error IsNot Nothing Then
_Logger.Warn("Unexpected error in running thread: " & e.Error.Message)
myLogger.Warn("Unexpected error in running thread: " & e.Error.Message)
End If
Catch ex As Exception
_Logger.Error(ex)
myLogger.Error(ex)
End Try
End Sub

View File

@ -69,7 +69,7 @@ Public Class Email
''' <param name="Folder">The folder to fetch messages from</param>
''' <param name="SearchCondition">Filter the search command. Defaults to `All`</param>
''' <returns>A list of Independentsoft.Email.Mime.Message objects</returns>
Public Function FetchIMAPMessages(Server As String, Port As Integer, Username As String, Password As String, Folder As String, Optional SearchCondition As S22.Imap.SearchCondition = S22.Imap.SearchCondition.All) As List(Of Message)
Public Function FetchIMAPMessages(Server As String, Port As Integer, Username As String, Password As String, Folder As String) As List(Of Message) ', Optional SearchCondition As S22.Imap.SearchCondition = S22.Imap.SearchCondition.All
Dim oMessages As New List(Of Message)
_logger.Debug("Connecting to Server {0}:{1} with user {2}", Server, Port, Username)
@ -260,6 +260,8 @@ Public Class Email
Public Function NewEmail(mailto As String, mailSubject As String, mailBody As String,
mailfrom As String, mailsmtp As String, mailport As Integer, mailUser As String, mailPW As String,
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()
@ -272,39 +274,38 @@ Public Class Email
For Each oMailReceipiant As String In oReceipiants
_logger.Debug($"oMailReceipiant [{oMailReceipiant}]")
_logger.Debug($"mailsmtp [{mailsmtp}]")
Dim sClient As Net.Mail.SmtpClient
Try
sClient = New Net.Mail.SmtpClient(mailsmtp, mailport)
myClient = New Net.Mail.SmtpClient(mailsmtp, mailport)
Catch ex As Exception
_logger.Warn($"Could not create SMTP-Client: [{ex.Message}]")
Return False
End Try
sClient.DeliveryMethod = SmtpDeliveryMethod.Network
myClient.DeliveryMethod = SmtpDeliveryMethod.Network
Dim mymesssage As New MailMessage
sClient.Port = mailport
myClient.Port = mailport
_logger.Debug($"mailport [{mailport}]")
If AUTH_TYPE = "SSL" Then
_logger.Debug("SSL = true")
sClient.EnableSsl = True
myClient.EnableSsl = True
Else
_logger.Debug("SSL = false")
sClient.EnableSsl = False
myClient.EnableSsl = False
End If
_logger.Debug($"mailUser [{mailUser}]")
sClient.Credentials = New NetworkCredential(mailUser, mailPW)
sClient.UseDefaultCredentials = False
myClient.Credentials = New NetworkCredential(mailUser, mailPW)
myClient.UseDefaultCredentials = False
If Test = True Then
mymesssage.Body = $"This is the body (text will be replaced within profile)! <br> mailsmtp: {mailsmtp} <br> mailport: {mailport} <br> mailUser: {mailUser} <br> mailPW: XXXX <br> AUTH_TYPE: {AUTH_TYPE}"
myMesssage.Body = $"This is the body (text will be replaced within profile)! <br> mailsmtp: {mailsmtp} <br> mailport: {mailport} <br> mailUser: {mailUser} <br> mailPW: XXXX <br> AUTH_TYPE: {AUTH_TYPE}"
Else
mymesssage.Body = mailBody
myMesssage.Body = mailBody
End If
_logger.Debug($"mailBody [{mailBody}]")
'mymesssage.IsBodyHtml = True
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(mymesssage.Body)
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(myMesssage.Body)
htmlView.ContentType = New System.Net.Mime.ContentType("text/html")
mymesssage.AlternateViews.Add(htmlView)
myMesssage.AlternateViews.Add(htmlView)
_logger.Debug($"attachmentString [{attachmentString}]")
If attachmentString <> "" Then
_logger.Info($"Attachment Path is: {attachmentString}")
@ -317,18 +318,18 @@ Public Class Email
'ElseIf attment.ToLower.EndsWith("docx") Then
' oAttachment.ContentType = New Independentsoft.Email.Mime.ContentType("application", "MS-word")
'End If
mymesssage.Attachments.Add(oAttachment)
myMesssage.Attachments.Add(oAttachment)
Else
_logger.Debug("No Attachment.")
End If
_logger.Debug($"mailfrom [{mailfrom}]")
mymesssage.From = New MailAddress(mailfrom)
myMesssage.From = New MailAddress(mailfrom)
_logger.Debug($"mailSubject [{mailSubject}]")
mymesssage.Subject = mailSubject
mymesssage.To.Add(New MailAddress(oMailReceipiant))
myMesssage.Subject = mailSubject
myMesssage.To.Add(New MailAddress(oMailReceipiant))
_logger.Debug($"Now Sending mail...")
sClient.Send(mymesssage)
myClient.Send(myMesssage)
_logger.Debug($"Mail has been sent!")
_logger.Info("Message to " & oMailReceipiant & " has been send.")
Next
@ -340,6 +341,22 @@ Public Class Email
Catch ex As Exception
_logger.Error(ex)
Try
_logger.Info("Unexpected error in Sending smtp-Mail: ")
If Not IsNothing(myClient) Then
_logger.Info($"myClient.Host: {myClient.Host.ToString}")
_logger.Info($"myClient.Port: {myClient.Port.ToString}")
_logger.Info($"myClient.EnableSsl: {myClient.EnableSsl.ToString}")
End If
If Not IsNothing(myMesssage) Then
_logger.Info($"myMesssage.Subject: {myMesssage.Subject.ToString}")
_logger.Info($"myMesssage.Body: {myMesssage.Body.ToString}")
_logger.Info($"myMesssage.From: {myMesssage.From.ToString}")
End If
Catch e1x As Exception
End Try
Return False
End Try