Reputation: 85
I'm having a problem using TidSMTP with TIdSSLIOHandlerSocketOpenSSL getting "Socket Error" just by connecting to the server.
Here's the Form Component Code
object IdSMTP: TIdSMTP
IOHandler = IdSSLIOHandlerSSL
Port = 465
SASLMechanisms = <>
UseTLS = utUseImplicitTLS
Left = 93
Top = 49
end
object IdSSLIOHandlerSSL: TIdSSLIOHandlerSocketOpenSSL
OnStatus = IdSSLIOHandlerSSLStatus
Destination = ':465'
MaxLineAction = maException
Port = 465
DefaultPort = 0
SSLOptions.Mode = sslmUnassigned
SSLOptions.VerifyMode = []
SSLOptions.VerifyDepth = 0
OnStatusInfo = IdSSLIOHandlerSSLStatusInfo
Left = 88
Top = 112
end
and Delphi Code
IdSMTP.Username := 'username';
IdSMTP.Password := 'password';
IdSMTP.Host := 'domain';
IdSMTP.Port := 465;
IdSMTP.UseTLS := utUseImplicitTLS;
try
IdSMTP.Connect;
except
on E:Exception do
// Socket Error, Connection Timeout is thrown.
Memo1.Lines.Add(E.Message);
end;
I logged SSL IO status and got this:
Resolving hostname {domain}.
Connecting to {ip}.
SSL status: "before/connect initialization"
SSL status: "before/connect initialization"
SSL status: "SSLv3 write client hello A"
SSL status: "SSLv3 read server hello A"
Socket Error # 10060
Connection timed out.
Our mail server is using self-signed certificate by the way.
What am i doing wrong?
TIA
UPDATE:07-02-2014
Tried Sending mail to Gmail using Indy tip but i get Connection Closed Gracefully sending the email also after SSLv3 read server hello A.
Resolving hostname smtp.gmail.com.
Connecting to 74.125.25.108.
Connected.
Sending Email..
SSL status: "before/connect initialization"
SSL status: "before/connect initialization"
SSL status: "SSLv3 write client hello A"
SSL status: "SSLv3 read server hello A"
Disconnected.
Connection Closed Gracefully.
Here's the new code:
IdSMTP.Username := 'username';
IdSMTP.Password := 'password';
IdSMTP.Host := 'smtp.gmail.com';
IdSMTP.UseTLS := utUseExplicitTLS;
IdSMTP.Port := 587;
try
// Can connect successfully
IdSMTP.Connect;
// This part throws the exception
IdSMTP.Send(IdMessage);
except
on E:Exception do
// Disconnected, connection closed gracefully
Memo1.Lines.Add(E.Message);
end;
UPDATE:
Tried sending email using Thunderbird connecting to same domain.
Thunderbird:
Indy:
No "client key exchange, ..." occurred on my program.
SOLVED
This isssue was resolved by Manually setting connectiontimeout
Upvotes: 3
Views: 5456
Reputation: 35
Please check that your firewall is temporarily disabled. I got to this page because I was having the same problem - immediate disconnection with "Connection closed gracefully" when doing SMTP with SSL. Then I disabled my Avast! firewall and it was fine.
Upvotes: 0
Reputation: 596352
You are using implicit SSL. That means an SSL handshake is initiated as soon as the socket is connected to the server, before any application data (SMTP commands/responses) are exchanged. A client hello is sent to the server, and then a timeout is occurring while waiting for the server to send back a hello in response. That implies that the server is NOT using SSL on the port you are connecting to.
Something to keep in mind - setting the UseTLS
property may change the Port
property, so make sure the Port
is actually what you are expecting when Connect()
is called. To make sure, try setting the Port
after setting the UseTLS
rather than before.
Upvotes: 3