Indy和smtps:无法连接 [英] Indy and smtps: cannot connect
问题描述
我正在尝试使用Indy从smtps(安全的smtp)发送电子邮件,并且技术过分地这是MarcoCantù的文章。
I am trying to send emails from smtps (secure smtp) using Indy and the technique exaplined in this Marco Cantù article.
这是我正在使用的:
object SMTP: TIdSMTP
IOHandler = IdSSLIOHandlerSocketOpenSSL1
SASLMechanisms = <>
UseTLS = utUseExplicitTLS
Left = 32
Top = 196
end
和
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);
我的程序挂在SMTP.Connect上,但没有任何异常或有用的错误。
i program hangs on SMTP.Connect, but without any exception or useful error.
如果我使用的不是Gmail,而是使用这篇文章所述的gmail设置,那么所有有效的方法
If instead than aboe i use gmail setings as explained in the article all works
您能给我个建议吗?
我的Indy 10.5.8和ssl dll与exe位于同一路径。
i have Indy 10.5.8 and the ssl dlls in the same path as the exe.
推荐答案
Connect()
挂起,因为您连接到错误的端口
具有错误的 UseTLS
属性分配。
Connect()
hangs because you are connecting to the wrong Port
with the wrong UseTLS
property assignment.
端口465是隐式SSL SMTP的端口,这意味着客户端必须在连接到服务器后立即加密连接,然后才能进行任何与SMTP相关的通信。服务器期望客户端发送SSL握手,但是客户端没有这样做,因为您设置了 UseTLS = utUseExplicitTLS
。这告诉 TIdSMTP
期望连接到服务器时最初不会对连接进行加密,然后 TIdSMTP
可以发送明确的 STARTTLS
命令发送到服务器,以便在需要时动态激活TLS加密。
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 tells TIdSMTP
to expect the connection to be initially unencrypted upon connecting to the server and then TIdSMTP
can send an explicit STARTTLS
command to the server to activate TLS encryption dynamically when needed.
因此, TIdSMTP
正在等待服务器发送SMTP问候,这是它从未执行过的,并且服务器希望您的客户端发送SSL握手,而它从未执行过。直到双方之一断开连接为止,都会发生死锁。
Thus, TIdSMTP
is 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.
如果连接到端口465,则必须设置 UseTLS = utUseImplicitTLS
代替。要使用 UseTLS = utUseExplicitTLS
,您需要连接到端口25或587。
If you connect to port 465, you must set UseTLS=utUseImplicitTLS
instead. To use UseTLS=utUseExplicitTLS
, you need to connect to port 25 or 587 instead.
这篇关于Indy和smtps:无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!