Search code examples
emailwindows-10smtpchilkat

Error when trying to send mail over smtp with Office 365 account


An application, which obviously uses Chilkat plugin, does not correctly send E-mails anymore using an Office 365 account. After a migration from on-premise exchange to Microsoft 365, the account and server settings were changed at end of March this year. Furthermore, client authentication needed to be disabled for the mailbox. After that, sending E-mails from the application had worked. Now, it again doesn't. Yesterday, one E-mail could successfully be sent after a computer restart - the next ones failed again.

I'm stuck to find the cause of the error and also I don't know, what data exactly is sent from the application during the connection, which makes the analysis more difficult.

I found this post mentioning that entries for TLS 1.0 need to be in the registry. Those were missing, but there were entries for TLS 1.2, so I didn't assume this is an issue, espccially because the entries concerning cryptography (also mentioned in the post) did already exist. In the meantime, I have added them nonetheless.

Below is the Chilkat Log, showing that - after the server is ready - the clientHandshake2 fails with error code 0x2746.

The support person of the application he couldn't find any problem and asked concerning that error code - what i assumed he should be able to examine. When I talked to him on the phone, I found out that he doesn't know more about Chilkat than I do. He mentioned an interesting point, which need to be double checked: As far as he was informed from the user directly - or how he had understood it - the error doesn't show up, if the user chooses another "Mandant" (client) in the application and sends E-mails from there.

Can someone help identify the cause of the error?

      SendEmail:
        DllDate: May 25 2017
        ChilkatVersion: 9.5.0.68
        UnlockPrefix: WERNERMAILQ
        Architecture: Little Endian; 32-bit
        Language: Visual C++ 2017 (32-bit)
        VerboseLogging: 0
        sendEmailInner:
          renderToMime:
            createEmailForSending:
              Auto-generating Message-ID
            --createEmailForSending
            renderToMime: Elapsed time: 0 millisec
          --renderToMime
          sendMimeInner:
            ensureSmtpSession:
              ensureSmtpConnection:
                SmtpHost: smtp.office365.com
                SmtpPort: 587
                SmtpUsername: [email protected]
                SmtpSsl: 0
                StartTLS: 1
                smtpConnect:
                  smtpHostname: smtp.office365.com
                  smtpPort: 587
                  connectionIsReady:
                    Need new SMTP connection
                  --connectionIsReady
                  smtpSocketConnect:
                    socketOptions:
                      SO_SNDBUF: 262144
                      SO_RCVBUF: 4194304
                      TCP_NODELAY: 1
                      SO_KEEPALIVE: 1
                    --socketOptions
                  --smtpSocketConnect
                  smtpGreeting:
                    readSmtpResponse:
                      SmtpCmdResp: 220 AM0PR02CA0163.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 23 Aug 2021 11:51:12 +0000
                    --readSmtpResponse
                  --smtpGreeting
                  startTLS:
                    sendCmdToSmtp:
                      SmtpCmdSent: EHLO EWGH-N-FV<CRLF>
                    --sendCmdToSmtp
                    readSmtpResponse:
                      SmtpCmdResp: 250-AM0PR02CA0163.outlook.office365.com Hello [213.221.219.37]
                      SmtpCmdResp: 250-SIZE 157286400
                      SmtpCmdResp: 250-PIPELINING
                      SmtpCmdResp: 250-DSN
                      SmtpCmdResp: 250-ENHANCEDSTATUSCODES
                      SmtpCmdResp: 250-STARTTLS
                      SmtpCmdResp: 250-8BITMIME
                      SmtpCmdResp: 250-BINARYMIME
                      SmtpCmdResp: 250-CHUNKING
                      SmtpCmdResp: 250 SMTPUTF8
                    --readSmtpResponse
                    sendCmdToSmtp:
                      SmtpCmdSent: STARTTLS<CRLF>
                    --sendCmdToSmtp
                    readSmtpResponse:
                      SmtpCmdResp: 220 2.0.0 SMTP server ready
                    --readSmtpResponse
                    clientHandshake:
                      clientHandshake2:
                        readHandshakeMessages:
                          WindowsError: Eine vorhandene Verbindung wurde vom Remotehost geschlossen.
                          WindowsErrorCode: 0x2746
                          maxToReceive: 5
                          Failed to receive data on the TCP socket
                          Failed to read beginning of SSL/TLS record.
                          b: 0
                          dbSize: 0
                          nReadNBytes: 0
                          idleTimeoutMs: 30000
                        --readHandshakeMessages
                      --clientHandshake2
                    --clientHandshake
                    Client handshake failed. (1)
                    connectionClosed: 0
                    Failed to establish TLS connection.
                  --startTLS
                --smtpConnect
              --ensureSmtpConnection
            --ensureSmtpSession
          --sendMimeInner
        --sendEmailInner
        Failed.
      --SendEmail
    --ChilkatLog
    
    23.08.2021  13:48:27    -F- Beim Versand der Lohnabrechnung per Email an Mitarbeiter(in) Nadine Aeschlimann ist ein Fehler aufgetreten!

Solution

  • In the meantime we could solve it.

    The reason was that the outgoing requests were blocked by the firewall. Strangely, a few of them went through, but not all. This is the reason why a network issue was initially not in the focus of our investigation.