From fa7fa40e1f842e0377b9eb61228e439304a146bd Mon Sep 17 00:00:00 2001 From: Developer01 Date: Mon, 29 Jun 2026 16:48:43 +0200 Subject: [PATCH] =?UTF-8?q?O=20Auth=20aus=20Oberf=C3=A4che?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../My Project/AssemblyInfo.vb | 4 +- App/EmailProfiler.Form/frmMain.vb | 43 +++++++++++-------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/App/EmailProfiler.Form/My Project/AssemblyInfo.vb b/App/EmailProfiler.Form/My Project/AssemblyInfo.vb index 3ca9ed2..569bdde 100644 --- a/App/EmailProfiler.Form/My Project/AssemblyInfo.vb +++ b/App/EmailProfiler.Form/My Project/AssemblyInfo.vb @@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices - + @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/App/EmailProfiler.Form/frmMain.vb b/App/EmailProfiler.Form/frmMain.vb index f1cc54c..3ef8cf3 100644 --- a/App/EmailProfiler.Form/frmMain.vb +++ b/App/EmailProfiler.Form/frmMain.vb @@ -770,53 +770,60 @@ Public Class frmMain ConfigManager.Save() My.Settings.Save() Cursor = Cursors.WaitCursor - Dim PWPlain = _Encryption.DecryptData(EMAIL_PWTextBox.Text) - 'NEW + _MailSender = New Mail.MailSender(LogConfig) Dim oDefault As Boolean = True If CheckBoxEnableTls1_1.Checked Or CheckBoxEnableTls1_2.Checked Then oDefault = False End If Dim oOptions As New Mail.MailSession.MailSessionOptions() With { - .EnableTls1_1 = CheckBoxEnableTls1_1.Checked, - .EnableTls1_2 = CheckBoxEnableTls1_2.Checked, - .EnableDefault = oDefault - } + .EnableTls1_1 = CheckBoxEnableTls1_1.Checked, + .EnableTls1_2 = CheckBoxEnableTls1_2.Checked, + .EnableDefault = oDefault + } Logger.Debug($"oOptions: oOptions.EnableTls1_1: {oOptions.EnableTls1_1}, oOptions.EnableTls1_2: {oOptions.EnableTls1_2}, oOptions.EnableDefault: {oOptions.EnableDefault}") - Dim oResult As Mail.MailSession.SessionInfo = _MailSender.Connect(EMAIL_SMTPTextBox.Text, PORTTextBox.Text, EMAIL_USERTextBox.Text, PWPlain, AUTH_TYPEComboBox.Text, oOptions) + + Dim oResult As Mail.MailSession.SessionInfo + + ' OAuth2 oder Standard-Authentifizierung + If AUTH_TYPEComboBox.Text = "OAUTH2" Then + ' OAuth2-Variablen aus DB-Feldern (analog zu btntestImap) + Dim oClientId = EMAIL_SMTPTextBox.Text + Dim oClientSecret = _Encryption.DecryptData(EMAIL_PWTextBox.Text) + Dim oTenantId = ARCHIVE_FOLDERTextBox.Text + Dim oUser = EMAIL_USERTextBox.Text + + oResult = _MailSender.ConnectToO365(oUser, oClientId, oTenantId, oClientSecret) + Else + ' Standard-Authentifizierung (bestehend) + Dim PWPlain = _Encryption.DecryptData(EMAIL_PWTextBox.Text) + oResult = _MailSender.Connect(EMAIL_SMTPTextBox.Text, PORTTextBox.Text, EMAIL_USERTextBox.Text, PWPlain, AUTH_TYPEComboBox.Text, oOptions) + End If If oResult.Connected = False Then Cursor = Cursors.Default MsgBox("Could not create a MailSession / connect to server. Please check the log.", MsgBoxStyle.Exclamation) Exit Sub End If + Dim oAddresses As List(Of String) = txtTestmail.Text.Split(";").ToList() Dim oAddedWhen = Now Dim oAttachments As New List(Of String) Dim oBody As String = $"This is just a template body (text will be replaced within the run) - ProfileID: {EMAILIDTextBox.Text}" Dim oMessageSent = _MailSender.SendMail(oAddresses, EMAIL_FROMTextBox.Text, "Testmail from EmailProfilerConfig", oBody, oAddedWhen, oAttachments, False) Cursor = Cursors.Default + If oMessageSent = True Then MsgBox("Email has been send successfully.", MsgBoxStyle.Information) Else MsgBox("Could not send the testmail. Please check the log.", MsgBoxStyle.Exclamation) End If - 'NEW END - - 'If _limilab.NewSMTPEmail(txtTestmail.Text, "Testmail", "This is the body (text will be replaced within profile)", EMAIL_FROMTextBox.Text, EMAIL_SMTPTextBox.Text, PORTTextBox.Text, - ' EMAIL_USERTextBox.Text, PWPlain, AUTH_TYPEComboBox.Text, "frmMain-Test", "", "", True) = True Then - - - ' MsgBox("Email has been send successfully.", MsgBoxStyle.Information) - 'Else - ' MsgBox("Could not send the testmail. Please check the log.", MsgBoxStyle.Exclamation) - 'End If End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btntestImap.Click ConfigManager.Save() - Dim oSQL = $"SELECT * FROM TBDD_EMAIL_ACCOUNT WHERE GUID = {EMAILIDTextBox.Text}" + Dim oSQL = $"SELECT * FROM TBDD_EMAIL_ACCOUNT (NOLOCK) WHERE GUID = {EMAILIDTextBox.Text}" Dim oDT As DataTable = _database.GetDatatable(oSQL) If Not IsNothing(oDT) Then