1
votes

A product I work on uses the Indy components to send emails. It is developed in RAD Studio XE4 (C++). I am trying to find out why it works on some computers but not on others. Of course, it works on my dev box. On the test box I either get a "connection closed gracefully" message or a socket error 10054.

Both machines are loading the same Indy files. My dev box is running Win 8.1 and the test box is running Win 7, so some of the Windows DLLs are different versions, but I doubt that is the problem.

I wrote a very simple test app, and it exhibits the same behavior.

The SMTP messages on my dev box look like this:

S: 220 smtp.gmail.com ESMTP vf11sm8649345igb.20 - gsmtp
C: EHLO ks-sayers-v60
S: 250-smtp.gmail.com at your service, [64.132.205.66]
S: 250-SIZE 35882577
S: 250-8BITMIME
S: 250-STARTTLS
S: 250-ENHANCEDSTATUSCODES
S: 250-PIPELINING
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
C: EHLO ks-sayers-v60
S: 250-smtp.gmail.com at your service, [64.132.205.66]
S: 250-SIZE 35882577
S: 250-8BITMIME
S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
S: 250-ENHANCEDSTATUSCODES
S: 250-PIPELINING
S: 250-CHUNKING
S: 250 SMTPUTF8

The SMTP messages on my test box look like this:

S: 220 smtp.gmail.com ESMTP s19sm631546ign.4 - gsmtp
C: EHLO ks-dsatest-v41
S: 250-smtp.gmail.com at your service, [64.132.205.66]
S: 250-SIZE  35882577
S: 250-8BITMIME
S: 250-STARTTLS
S: 250-ENHANCEDSTATUSCODES
S: 250-PIPELINING
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
C: QUIT

I'm using the same gmail user and password in both tests. I am not sure why my test app is sending a QUIT message on the test box instead of an EHLO.

Any help or ideas what to look at will be greatly appreciated!

RAD Studio XE4

Indy 10.6.0.4975

ssleay32.dll/libeay32.dll are v1.0.0g

Test code:

void __fastcall TForm1::btnSendClick(TObject *Sender)
{
    IdLogFile1->Active = true;

    try
    {
        try
        {
            IdSMTP1->ConnectTimeout = 30000;
            IdSMTP1->Username = edtFrom->Text;
            IdSMTP1->Password = edtPassword->Text;
            IdMessage1->Recipients->Clear();
            IdMessage1->Recipients->Add();
            IdMessage1->Recipients->Items[0]->Address = edtTo->Text;

            IdSMTP1->Connect();
            if (IdSMTP1->Connected())
            {
                IdSMTP1->Send(IdMessage1);
            }
            LogSmtpSettings();
        }
        catch (Exception & e)
        {
            LogSmtpSettings();
            throw Exception(e.Message);
        }
    }
    __finally
    {
        IdLogFile1->Active = false;
    }
}

Here are the properties of the TIdSMTP component:

Indy Version:        10.6.0.4975
Host:                smtp.gmail.com
Port:                587
HELO Name:           
Mail Agent:          
IOHandler:           TIdSSLIOHandlerSocketOpenSSL
Connection Timeout:  30000
Read Timeout:        -1
Authentication Type: Default
Validate Auth Login: True
Username:            '[email protected]'
Use EHLO:            True
TLS:                 Explicit TLS
Use Nagle:           True
Use Pipelining:      True
Use VERP:            False
VERP Delimiters:     none
Intercept:           TIdLogFile
Intercept IsClient:  True
Supports TLS:        True
Last Command Result: Ready to start TLS
1
I don't know this library, but do you need to check for certificate errors?user253751
When re-throwing an exception, you should be using throw; instead of throw Exception(e.Message);. The latter loses all kinds of useful information.Remy Lebeau
Thanks for the input!steve ayers

1 Answers

0
votes

The fact that your test box is sending a QUIT command immediately after receiving a STARTTLS success reply means the TLS handshake is failing. TIdSMTP calls Disconnect() on itself before then raising a TLS exception into your code saying that the handshake failed.

Also, you are using an older release of Indy 10. TIdSMTP was updated in mid-2014 to no longer send QUIT if the TLS handshake fails. You say you are using 10.6.0.4975, the current version (at the time of this writing) is 10.6.2.5339.

Now, as for why the TLS handshake is failing is anyone's guess, since you have not provided any details about your setup to diagnose that issue with. Maybe you have not configured TIdSMTP correctly for TLS. Maybe you don't have the correct SSL/TLS DLLs installed with your app. Who knows. Please provide those details.