I am trying to send emails from smtps (secure smtp) using Indy and the technique exaplined in this Marco Cantù article.
This is what I am using:
object SMTP: TIdSMTP
IOHandler = IdSSLIOHandlerSocketOpenSSL1
SASLMechanisms = <>
UseTLS = utUseExplicitTLS
Left = 32
Top = 196
end
and
SMTP.Host := 'smtps.pec.aruba.it';;
SMTP.Port := 465;;
SMTP.Username := 'myaddress@pec.it';
SMTP.Password := 'myPassw0rd';
MailMessage.Encoding := meDefault;
MailMessage.From.Address := 'myaddress@pec.it';
MailMessage.BccList.EMailAddresses := 'testaddress0@gmail.com';
MailMessage.Subject := 'Test Mail';
MailMessage.Body.Text := 'Please ignore this mail, This is a test';
SMTP.Connect; //failure!!!
SMTP.Send(MailMessage);
i program hangs on SMTP.Connect, but without any exception or useful error.
If instead than aboe i use gmail setings as explained in the article all works
Can you please give an advice?
i have Indy 10.5.8 and the ssl dlls in the same path as the exe.
Connect()hangs because you are connecting to the wrongPortwith the wrongUseTLSproperty assignment.Port 465 is the implicit SSL port for SMTP, meaning the client must encrypt the connection immediately upon connecting to the server before any SMTP-related communication can occur. The server is expecting your client to send an SSL handshake, but your client is not doing that because you set
UseTLS=utUseExplicitTLS. That tellsTIdSMTPto expect the connection to be initially unencrypted upon connecting to the server and thenTIdSMTPcan send an explicitSTARTTLScommand to the server to activate TLS encryption dynamically when needed.Thus,
TIdSMTPis waiting for the server to send an SMTP greeting, which it never does, and the server is expecting your client to send an SSL handshake, which it never does. A deadlock occurs until one of the parties disconnects.If you connect to port 465, you must set
UseTLS=utUseImplicitTLSinstead. To useUseTLS=utUseExplicitTLS, you need to connect to port 25 or 587 instead.