德尔福+ Indy:连接优雅关闭

发布于 2024-07-25 18:31:50 字数 450 浏览 8 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

电影里的梦 2024-08-01 18:31:50

请在 http://www.swissdelphicenter.ch/en/showarticle 上阅读所有相关内容。 php?id=1

EIdConnClosedGraceively 是一个
异常信号表明
连接已被关闭
对方是故意的。 这不是
与断开的连接相同
会导致连接重置错误。
如果对方已经关闭了
连接并且套接字被读取或
写入 EIdConnClosedGraceively
将由印地抚养。 这是
类似于尝试读取或写入
到一个已经关闭的文件
你的知识。

在某些情况下,这是一个真正的例外
并且您的代码需要处理它。 在
其他情况(通常是服务器)这个
是功能的正常部分
协议和 Indy 处理这个
对你来说例外。 尽管印地
在 IDE 中运行时捕获它
调试器将首先被触发。
您只需按 F9 即可继续
Indy 将处理异常,
但期间不断停止
调试可能非常烦人。 在
印地抓住的情况
例外,您的用户永远不会看到
程序中的异常,除非
从 IDE 运行。

Read all about it on http://www.swissdelphicenter.ch/en/showarticle.php?id=1

EIdConnClosedGracefully is an
exception signaling that the
connection has been closed by the
other side intentionally. This is not
the same as a broken connection which
would cause a connection reset error.
If the other side has closed the
connection and the socket is read or
written to, EIdConnClosedGracefully
will be raised by Indy. This is
similar to attempting to read or write
to a file that has been closed without
your knowledge.

In some cases this is a true exception
and your code needs to handle it. In
other cases (typically servers) this
is a normal part of the functioning of
the protocol and Indy handles this
exception for you. Even though Indy
catches it, when running in the IDE
the debugger will be triggered first.
You can simply press F9 to continue
and Indy will handle the exception,
but the constant stopping during
debugging can be quite annoying. In
the cases where Indy catches the
exception, your users will never see
an exception in your program unless it
is run from the IDE.

失去的东西太少 2024-08-01 18:31:50

在我的例子中,错误是因为我使用的发件人电子邮件地址来自与 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.

无语# 2024-08-01 18:31:50

根据我的经验,如果是 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 the MAIL FROM. More info can be determined by logging the error using TIdLogEvent for these users that receive it, otherwise the error report is rather vague - if the disconnect (Connection closed gracefully) occurs right after the MAIL 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.

终陌 2024-08-01 18:31:50

当客户端尚未安装 OpenSSL 库时,我们收到此错误

We got this error when the OpenSSL libraries hadn't been installed at the client site

夜无邪 2024-08-01 18:31:50

我知道它很旧等等,但我已经完成了这个例外。

就我而言,服务器阻止了邮件发送,因为我超出了托管服务的每日发送限制。 测试某些东西时很容易超出这些限制。 异常本身是不明确的,因此可能有更多原因,但我会首先检查这个问题。 它为我解决了问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文