This commit is contained in:
Jonathan Jenne 2022-10-24 13:17:38 +02:00
commit 882824d80f
3 changed files with 25 additions and 11 deletions

View File

@ -294,9 +294,12 @@ Public Class Email
_logger.Debug("SSL = false") _logger.Debug("SSL = false")
myClient.EnableSsl = False myClient.EnableSsl = False
End If End If
_logger.Debug($"mailUser [{mailUser}]") If mailUser <> String.Empty Then
myClient.Credentials = New NetworkCredential(mailUser, mailPW) _logger.Debug($"mailUser [{mailUser}]")
myClient.UseDefaultCredentials = False myClient.Credentials = New NetworkCredential(mailUser, mailPW)
myClient.UseDefaultCredentials = False
End If
If Test = True Then 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}"

View File

@ -69,9 +69,10 @@ Public Class Email2
pSMTP.StartTLS() pSMTP.StartTLS()
End If End If
Logger.Debug("Connection to SMTP Server [{0}] established!", pServer) Logger.Debug("Connection to SMTP Server [{0}] established!", pServer)
If pUsername <> String.Empty Then
Logger.Debug("Logging in with user [{0}]", pUsername) Logger.Debug("Logging in with user [{0}]", pUsername)
pSMTP.UseBestLogin(pUsername, pPassword) pSMTP.UseBestLogin(pUsername, pPassword)
End If
Return pSMTP Return pSMTP

View File

@ -14,6 +14,7 @@ Public Class MailSender
Private AuthType As String Private AuthType As String
Private Session As Smtp = Nothing Private Session As Smtp = Nothing
Public Connected2Server As Boolean = False
Const SMTP_IGNORED_ERRORS As SslPolicyErrors = Const SMTP_IGNORED_ERRORS As SslPolicyErrors =
SslPolicyErrors.RemoteCertificateChainErrors Or ' self-signed SslPolicyErrors.RemoteCertificateChainErrors Or ' self-signed
@ -39,7 +40,7 @@ Public Class MailSender
Password = pPassword Password = pPassword
AuthType = pAuthType AuthType = pAuthType
Logger.Info("Connecting to Server..") Logger.Debug("Connecting to Server..")
Logger.Debug("SMTP Server: [{0}]", Server) Logger.Debug("SMTP Server: [{0}]", Server)
Logger.Debug("SMTP Port: [{0}]", Port) Logger.Debug("SMTP Port: [{0}]", Port)
Logger.Debug("SMTP User: [{0}]", User) Logger.Debug("SMTP User: [{0}]", User)
@ -108,9 +109,10 @@ Public Class MailSender
End If End If
Try Try
Logger.Info("Logging in with user [{0}]", pUser) If pUser <> String.Empty Then
oSession.UseBestLogin(pUser, pPassword) Logger.Info("Logging in with user [{0}]", pUser)
oSession.UseBestLogin(pUser, pPassword)
End If
Catch ex As Exception Catch ex As Exception
Logger.Warn("Error while connecting with Auth type PLAINTEXT!") Logger.Warn("Error while connecting with Auth type PLAINTEXT!")
Logger.Error(ex) Logger.Error(ex)
@ -119,7 +121,7 @@ Public Class MailSender
End Try End Try
Session = oSession Session = oSession
Connected2Server = True
Return True Return True
End Function End Function
@ -175,6 +177,10 @@ Public Class MailSender
Private Function SendMailTo(pSession As Smtp, pSendTo As String, pSendFrom As String, pSubject As String, pBody As String, pCreationTime As Date, pAttachments As List(Of String), pTest As Boolean) Private Function SendMailTo(pSession As Smtp, pSendTo As String, pSendFrom As String, pSubject As String, pBody As String, pCreationTime As Date, pAttachments As List(Of String), pTest As Boolean)
Try Try
If IsNothing(pSession) Then
Logger.Info("ATTENTION-ERROR: pSession is nothing!")
Return False
End If
Logger.Debug("Preparing to send mail to [{0}]", pSendTo) Logger.Debug("Preparing to send mail to [{0}]", pSendTo)
Dim oMailBuilder As New Limilabs.Mail.MailBuilder() Dim oMailBuilder As New Limilabs.Mail.MailBuilder()
@ -189,6 +195,10 @@ Public Class MailSender
oMailBuilder = AddAttachments(oMailBuilder, pAttachments) oMailBuilder = AddAttachments(oMailBuilder, pAttachments)
Logger.Debug("Now sending mail..") Logger.Debug("Now sending mail..")
If IsNothing(oMailBuilder) Then
Logger.Info("ATTENTION-ERROR: oMailBuilder is nothing!")
Return False
End If
Dim oMail = oMailBuilder.Create() Dim oMail = oMailBuilder.Create()
pSession.SendMessage(oMail) pSession.SendMessage(oMail)
Logger.Info("Mail to [{0}] has been sent.", pSendTo) Logger.Info("Mail to [{0}] has been sent.", pSendTo)