【问题标题】:Using INDY 10 with Exchange SMTP-Server将 INDY 10 与 Exchange SMTP 服务器一起使用
【发布时间】:2013-09-03 16:40:51
【问题描述】:

从上一个问题here 我了解了如何使用 INDY SMTP (TIdSMTP) 使用 Office 365 帐户发送邮件。我也为许多其他人找到了它,它适用于几乎所有常见的电子邮件提供商。但我不知道如何将它与我的本地 Exchange Server 一起使用。前段时间有 indy 附带的 SASL-NTLM 组件,但似乎它们已被删除。我需要 NTLM 连接到本地 Exchange Server。但如果没有 NTLM,我无法弄清楚如何做到这一点。

【问题讨论】:

  • 您遇到了什么具体问题?如果您不解释“那个问题”是什么,我们很难就如何解决它提供建议。请edit您的问题并提出更具体的问题,以便我们尝试帮助您解决。
  • 对 NTLM SASL 的支持未删除。它一开始就没有最终确定。 TIdSASLNTLM 组件仍然存在,在IdSASL_NTLM.pas 单元中,它只是默认没有注册在组件面板上,但是您可以在代码中可编程地实例化它。
  • @RemyLebeau:我的 INDY 版本(XE2 附带的 Indy 10)中不存在“IdSASL_NTLM.pas”。我只是拥有“IdNTLM.pas”。 {at} KenWhite:明天我会补充我在使用其他 SALS 方法(或者干脆没有 SASL)时遇到的错误,带有交换服务器的机器不在家里。

标签: delphi email smtp exchange-server indy


【解决方案1】:

我最近也在为 Indy 和我的 Exchange 服务器而苦恼。 SaslNtlm 组件不在 Delphi XE5 附带的 Indy10 版本中。它甚至不在 Indy Protocols 文件夹的源文件中。

幸运的是,使用 SMTP 客户端进行 NTLM 身份验证所需的许多东西都可用。有一个名为 IdAuthenticationSSPI 的单元实现了整个 NTLM 交换。剩下要做的就是实现 TIdSASL 的自定义后代,它与 TIndySSPINTLMClient 对象交互。

  TSaslNtlm = class(TIdSASL)
  public
    constructor Create(AOwner: TComponent);
    destructor Destroy; override;

    function StartAuthenticate(const AChallenge, AHost, AProtocolName : string): string; override;
    function ContinueAuthenticate(const ALastResponse, AHost, AProtocolName : string): string; override;
    function IsReadyToStart: Boolean; override;

    class function ServiceName: TIdSASLServiceName; override;

  private
    FSSPIClient: TIndySSPINTLMClient;
  end;

类的实现如下:

constructor TSaslNtlm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FSSPIClient := TIndySSPINTLMClient.Create;
end;

destructor TSaslNtlm.Destroy;
begin
  FSSPIClient.Free;
  inherited;
end;

function TSaslNtlm.StartAuthenticate(const AChallenge, AHost,
                                     AProtocolName: string): string;
begin
  FSSPIClient.SetCredentials(AHost, '', '');
  Result := BytesToStringRaw(FSSPIClient.InitAndBuildType1Message);
end;

function TSaslNtlm.ContinueAuthenticate(const ALastResponse, AHost,
                                        AProtocolName: string): string;
var LastMsg: TIdBytes;
begin
  LastMsg := ToBytes(ALastResponse, Indy8BitEncoding
                     {$IFDEF STRING_IS_ANSI}, Indy8BitEncoding{$ENDIF});
  Result := BytesToStringRaw(FSSPIClient.UpdateAndBuildType3Message(LastMsg));
end;

function TSaslNtlm.IsReadyToStart: Boolean;
begin
  Result := True;
end;

class function TSaslNtlm.ServiceName: TIdSASLServiceName;
begin
  Result := 'NTLM';
end;

然后只需将这种 SASL 机制添加到 SMTP 客户端即可:

smtp.AuthType := satSASL;
ntml := TSaslNtlm.Create(smtp);
with smtp.SASLMechanisms.Add do begin
  DisplayName := ntlm.ServiceName;
  SASL := ntlm;
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-18
    • 2020-08-05
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-31
    相关资源
    最近更新 更多