德尔福+ Indy:连接优雅关闭
使用 D7 + Indy 10 最新版本。
我的代码使用 TIdSMTP 发送电子邮件。 我不断收到一些最终用户的“连接正常关闭”的消息,但电子邮件从未发送。
代码如下:
try
~~~~
~~~~
_idSMTP := TIdSmtp.Create;
with _idSMTP do
begin
Host := 'myhost';
Connect;
try
Send(_EmailMsg);
Result := True;
except
on E: Exception do
begin
MsgDlgErr(Self.Handle, E.Message)
end
end;
end;
finally
_idSMTP.Disconnect;
_idSMTP.Free;
end;
有什么建议吗?
Using D7 + Indy 10 latest build.
My code is using TIdSMTP to send email.
I keep getting "Connection closed gracefully" at some end-users, and the email is never sent.
The code is like:
try
~~~~
~~~~
_idSMTP := TIdSmtp.Create;
with _idSMTP do
begin
Host := 'myhost';
Connect;
try
Send(_EmailMsg);
Result := True;
except
on E: Exception do
begin
MsgDlgErr(Self.Handle, E.Message)
end
end;
end;
finally
_idSMTP.Disconnect;
_idSMTP.Free;
end;
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请在 http://www.swissdelphicenter.ch/en/showarticle 上阅读所有相关内容。 php?id=1
Read all about it on http://www.swissdelphicenter.ch/en/showarticle.php?id=1
在我的例子中,错误是因为我使用的发件人电子邮件地址来自与 smtp 服务器托管的域不同的域,这就是 smtp 服务器拒绝连接的原因。
In my case the error was caused because I used a sender email address from a different domain than the one hosted by the smtp server, that's why the smtp server rejected the connection.
根据我的经验,如果是 AT&T 服务器,它会拒绝
MAIL FROM
中的@att.net
地址以外的电子邮件地址。 可以通过使用TIdLogEvent
为接收错误的用户记录错误来确定更多信息,否则错误报告相当模糊 - 如果在MAIL FROM 之后立即发生断开连接(连接正常关闭)
那么它可能表明服务器策略拒绝其不托管的域的电子邮件,正如托尼所解释的那样。否则,“连接正常关闭”错误意味着正在尝试读取/写入已被对等方故意关闭的套接字 - 在您的情况下,对等方是您连接到的 SMTP 服务器。 它与指示连接断开的“连接重置”错误不同。 在这两种情况下,连接都不再存在,您无法再对其进行读/写。
In my experience, in case of AT&T server, it rejects an email address which is not
@att.net
address in theMAIL FROM
. More info can be determined by logging the error usingTIdLogEvent
for these users that receive it, otherwise the error report is rather vague - if the disconnect (Connection closed gracefully) occurs right after theMAIL FROM
then it might indicate a server policy rejecting an email with the domain which it doesn't host as explained by Toni as well.Otherwise the "Connection closed gracefully" error means that an attempt is being made to read/write to socket that has been closed by the peer intentionally - in your case, peer is the SMTP server you connect to. It is different than the "Connection reset" error which indicates a broken connection. In both cases, the connection is no longer present and you can't read/write anymore to it.
当客户端尚未安装 OpenSSL 库时,我们收到此错误
We got this error when the OpenSSL libraries hadn't been installed at the client site
我知道它很旧等等,但我已经完成了这个例外。
就我而言,服务器阻止了邮件发送,因为我超出了托管服务的每日发送限制。 测试某些东西时很容易超出这些限制。 异常本身是不明确的,因此可能有更多原因,但我会首先检查这个问题。 它为我解决了问题。
I know it's old and so on, but i've done with this exeption already.
In my case, the server was blocking send of mail because I exceeded the daily send limits for the hosting service. It's easy to exceed these limits when testing something. The exception itself is ambiguous, so there may be more reasons, but I would start by checking this issue first. It solved the problem for me.