【解決方法】Accessプロジェクトのcom DLLのVb.netメールメッセージがWindows 11から機能しない

[ad_1]

Several years ago I created a simple com object in vb.net for use with an MS Access project for one of my clients. It's worked just fine for several years on Windows 10 for them. Now they have a couple of Windows 11 computers in their office and it doesn't work on either one. They are all on the same network. They don't have any other issues with anything else as far as I know. In one of the MS Access tables I'm storing the outgoing email credentials that are sent along with a subject, body, and list of recipients to the com object.

Like I said, all this has worked just fine on Windows 10 for 7 years.

Does anyone have any ideas about this?

Here's pretty much the entirety of my code:
VB
<pre>Public Function pubfncSendEmail(
        emailToAddresses As String, emailToDisplayNamees As String,
        emailCCAddresses As String, emailCCDisplayNamees As String,
        emailBCCAddresses As String, emailBCCDisplayNamees As String,
        emailFromAddress As String, emailFromDisplayName As String,
        emailSenderAddress As String, emailSenderDisplayName As String,
        emailReplyToAddress As String, emailReplyToDisplayName As String,
        smtpHost As String, smtpUserName As String,
        smtpPassword As String, smtpPortNum As String, useSSL As Boolean,
        emailSubject As String, emailBody As String,
        priorityLevel As Int32, readRequest As Boolean,
        attachmentList As String
    ) As String

        'emailToAddresses is a string of one or more separated by semicolons

        Dim aEmailToAddresses() As String = Nothing
        Dim aEmailToDisplayNames() As String = Nothing

        Dim aEmailCCAddresses() As String = Nothing
        Dim aEmailCCDisplayNames() As String = Nothing

        Dim aEmailBCCAddresses() As String = Nothing
        Dim aEmailBCCDisplayNames() As String = Nothing

        Dim aAttachmentList() As String = Nothing

        Dim pl As MailPriority

        Dim emailSendFailure As String = ""

        Try

            If emailToAddresses <> "" Then
                aEmailToAddresses = emailToAddresses.Split(";")
                aEmailToDisplayNames = emailToDisplayNamees.Split(";")
            End If

            If emailCCAddresses <> "" Then
                aEmailCCAddresses = emailCCAddresses.Split(";")
                aEmailCCDisplayNames = emailCCDisplayNamees.Split(";")
            End If

            If emailBCCAddresses <> "" Then
                aEmailBCCAddresses = emailBCCAddresses.Split(";")
                aEmailBCCDisplayNames = emailBCCDisplayNamees.Split(";")
            End If

            If attachmentList <> "" Then
                aAttachmentList = attachmentList.Split(";")
            End If

            Select Case priorityLevel
                Case 0
                    pl = MailPriority.Normal
                Case 1
                    pl = MailPriority.Low
                Case 2
                    pl = MailPriority.High
            End Select

            Dim smtpClient As New SmtpClient
            Dim smtpCredentials As New Net.NetworkCredential(smtpUserName, AES_DecryptString(smtpPassword, "blah"))
            Dim EmailMsg As New MailMessage()

            EmailMsg.From = New MailAddress(emailFromAddress, emailFromDisplayName)
            EmailMsg.Sender = New MailAddress(emailSenderAddress, emailSenderDisplayName)
            Dim replyToAddress As New MailAddress(emailReplyToAddress, emailReplyToDisplayName)
            EmailMsg.ReplyToList.Add(replyToAddress)

            Dim i As Integer

            If emailToAddresses <> "" Then
                For i = 0 To aEmailToAddresses.Length - 1
                    EmailMsg.To.Add(New MailAddress(aEmailToAddresses(i).Trim, aEmailToDisplayNames(i).Trim))
                Next
            End If

            If emailCCAddresses <> "" Then
                For i = 0 To aEmailCCAddresses.Length - 1
                    EmailMsg.CC.Add(New MailAddress(aEmailCCAddresses(i).Trim, aEmailCCDisplayNames(i).Trim))
                Next
            End If

            If emailBCCAddresses <> "" Then
                For i = 0 To aEmailBCCAddresses.Length - 1
                    EmailMsg.Bcc.Add(New MailAddress(aEmailBCCAddresses(i).Trim, aEmailBCCDisplayNames(i).Trim))
                Next
            End If

            If attachmentList <> "" Then
                For i = 0 To aAttachmentList.Length - 1
                    EmailMsg.Attachments.Add(New Attachment(aAttachmentList(i), MediaTypeNames.Application.Octet))
                Next
            End If

            EmailMsg.Subject = emailSubject
            EmailMsg.Body = emailBody
            EmailMsg.Priority = pl
            EmailMsg.Headers.Add("Disposition-Notification-To", emailFromAddress)

            EmailMsg.IsBodyHtml = True
            EmailMsg.BodyEncoding = System.Text.Encoding.UTF8

            smtpClient.UseDefaultCredentials = False
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
            smtpClient.EnableSsl = useSSL
            smtpClient.Host = smtpHost
            smtpClient.Port = smtpPortNum
            smtpClient.Credentials = smtpCredentials

            smtpClient.Send(EmailMsg)

            emailSendFailure = ""

        Catch ex As Exception
            emailSendFailure = ex.Message.ToString & Environment.NewLine & Environment.NewLine & ex.StackTrace.ToString

        End Try

        Return emailSendFailure

    End Function

    Public Function AES_EncryptString(ByVal input As String, ByVal pass As String) As String

        ' "input" is the password to encrypt
        ' "pass" is the value used to do the encryption (like a salt)

        Dim encrypted As String = ""

        Try

            Dim AES As New System.Security.Cryptography.RijndaelManaged
            Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
            Dim hash(31) As Byte
            Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))

            Array.Copy(temp, 0, hash, 0, 16)
            Array.Copy(temp, 0, hash, 15, 16)
            AES.Key = hash
            AES.Mode = Security.Cryptography.CipherMode.ECB

            Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
            Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)

            encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))

        Catch ex As Exception
            encrypted = ex.Message.ToString & Environment.NewLine & Environment.NewLine & ex.StackTrace.ToString

        End Try

        Return encrypted

    End Function

    Public Function AES_DecryptString(ByVal input As String, ByVal pass As String) As String

        ' "input" is the password to encrypt
        ' "pass" is the value used to do the encryption (like a salt)

        Dim decrypted As String = ""

        Try

            Dim AES As New System.Security.Cryptography.RijndaelManaged
            Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
            Dim hash(31) As Byte
            Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))

            Array.Copy(temp, 0, hash, 0, 16)
            Array.Copy(temp, 0, hash, 15, 16)
            AES.Key = hash
            AES.Mode = Security.Cryptography.CipherMode.ECB

            Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor
            Dim Buffer As Byte() = Convert.FromBase64String(input)

            decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))

        Catch ex As Exception
            decrypted = ex.Message.ToString & Environment.NewLine & Environment.NewLine & ex.StackTrace.ToString

        End Try

        Return decrypted

    End Function

ありがとう!

私が試したこと:

The error message on the Windows 11 machines when the Send method is executed is very useless. It simply says "failure sending mail" and the stack trace only regurgitates the list of parameters for my function in vb.net. There's nothing at all useful in the error information.
I updated my com object to use framework 4.8 and checked the Windows 11 machines to be sure they were up to date on this as well. That's all good.

解決策 1

すべての詳細を表示する必要があります Exception あなたの中で Catch ブロック、特に Exception.InnerException プロパティ (システム) Microsoft Learn[^]。

推奨する「備考」セクションも参照してください。 いいえ を使用して SmtpClient クラス (System.Net.Mail) | Microsoft Learn[^]。

解決策 2

ちょっと問題があります。 SmtpMail クライアントは非推奨になりました。 から SmtpClient のドキュメント[^]:

引用:

重要

SmtpClient は多くの最新プロトコルをサポートしていないため、新規開発に SmtpClient クラスを使用することはお勧めしません。 代わりに MailKit または他のライブラリを使用してください。 詳細については、「」を参照してください。 SmtpClient は使用しないでください[^] GitHub 上で。

「最新のプロトコルをサポートしていない」ということは、サーバーがサポートしなくなった非推奨のハッシュ、暗号化、および SSL バージョンを SmtpClient がサポートしていることも意味します。

[ad_2]

コメント

タイトルとURLをコピーしました