0
votes

I have a problem sending gmail smtp mail with indy on delphi XE3 build (Version 17.0.4770.56661)

I can smooth send my laptop but other pc's give a error like "connection closed gracefully"

I add a idlogfile component on my form and give me this line

Recv 18.04.2013 11:17:20: 220 mx.google.com ESMTP s47sm13947715eeg.8 - gsmtp<EOL>
Sent 18.04.2013 11:17:20: EHLO S23-101<EOL>
Recv 18.04.2013 11:17:20: 250-mx.google.com at your service, [195.175.87.XX]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250 ENHANCEDSTATUSCODES<EOL>
Sent 18.04.2013 11:17:20: STARTTLS<EOL>
Recv 18.04.2013 11:17:21: 220 2.0.0 Ready to start TLS<EOL>
Sent 18.04.2013 11:17:21: QUIT<EOL>

And I use this code on my app

IdSMTP1.host:='smtp.gmail.com'  ;
    IdSMTP1.username:='[email protected]';
    IdSMTP1.Password:='XXXX';
    IdSMTP1.port:=587;
    IdSMTP1.UseTLS:=utUseExplicitTLS;
    IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmClient;
    IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method:= sslvTLSv1;
    IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth := 2;
    IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyMode := [];
    IdSSLIOHandlerSocketOpenSSL1.Host := IdSMTP1.Host;
    IdSSLIOHandlerSocketOpenSSL1.Port := IdSMTP1.Port;

    IdMessage1.From.address := '[email protected]';
    IdMessage1.CClist.EMailAddresses:= edit5.Text;
    IdMessage1.Subject:= 'Subject is here';
    IdMessage1.Body.Clear;
    Idmessage1.Body.Add('Body is here');
    for Z := 0 to ListBox8.Items.Count-1 do begin
      TIdAttachmentFile.Create(IdMessage1.MessageParts,ListBox8.Items[Z]);
    end;
    IdSMTP1.Connect;
    IdSMTP1.Authenticate;
    try
        try
            idSMTP1.Send(IdMessage1);
        except on E:Exception do
            Memo1.Lines.Insert(0, 'ERROR: ' + E.Message);
        end;
    finally
        if idSMTP1.Connected then idSMTP1.Disconnect;
    end;

Please help me

Thanks :)

2
for what i remember, GMail pop interfaces demand using SSL/TLS. Check that firewall or antivirus does not kill encrypted mail traffic (had issues with Avira). Check that date, time and timezone are set correctly.Arioch 'The
Hi arioch, I use not any firewall or antivirus and i try a lot of pcCeRBeR

2 Answers

0
votes

When a QUIT command is sent immediately after the STARTTLS response is received, that means an exception was raised during the actual SSL/TLS handshake. TIdSMTP.Connect() catches the exception, calls Disconnect() (sending an unencrypted QUIT since SSL/TLS is not active 1), and then re-raises the exception into your code. So you need to check what exception is actually being raised. A "connection closed gracefully" exception means the connection was closed on the other end, either by the server itself, or maybe by a firewall/router that is sitting in the middle of the connection.


Update:

1: TIdSMTP was updated in SVN rev 5156 in 2014 to no longer send an unencrypted QUIT when closing the socket due to a SSL/TLS handshake failure, since the socket is in an indeterminate state by that point.

-1
votes

You must "Allow less secure applications access yoputr account" in the configuration of your account. Google hacve added some restrictions in this way.

See this link in Google documentation.