向 gmail 发送消息失败,并显示“启动 SSL 协商命令失败”。错误

发布于 2024-10-31 23:01:09 字数 1442 浏览 0 评论 0原文

我遵循的提示可以在此处找到。

我在 win32 文件夹中有 libeay32.dll 和 ssleay32.dll 。

dfm 文件:

object tidSMTP: TIdSMTP
    IOHandler = tidSMTP_SSL
    SASLMechanisms = <>
    UseTLS = utUseExplicitTLS
  end
  object tidSMTP_SSL: TIdSSLIOHandlerSocketOpenSSL
    Destination = 'smtp.gmail.com:587'
    Host = 'smtp.gmail.com'
    MaxLineAction = maException
    Port = 587
    DefaultPort = 0
    SSLOptions.Mode = sslmUnassigned
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0
  end

和发送按钮单击事件:

procedure TForm1.btnSendClick(Sender: TObject);
var
  mes:TIdMessage;
  fromAddress:TIdEmailAddressItem;
  toAddress:TIdEMailAddressItem;
begin
  tidSMTP.Username := txtUsername.Text;
  tidSMTP.Password := txtPassword.Text;
  tidSMTP.Host := txtSMTPserver.Text;           //smtp.gmail.com
  tidSMTP.Port := StrToInt(txtSMTPport.Text);   //587

  fromAddress := TIdEMailAddressItem.Create;
  fromAddress.Address := txtUsername.Text;

  toAddress := TIdEMailAddressItem.Create;
  toAddress.Address := txtTo.Text;

  mes := TIdMessage.Create;
  mes.ContentType := 'text/plain';
  mes.From := fromAddress;
  mes.ReceiptRecipient := toAddress;
  mes.Subject := txtSubject.Text;

  mes.Body := memoText.Lines;

  tidSMTP.Connect;
  tidSMTP.Send(mes);
  tidSMTP.Disconnect;
end;

任何帮助将不胜感激!

Tips i followed is found here.

I do have libeay32.dll and ssleay32.dll in win32 folder.

dfm file:

object tidSMTP: TIdSMTP
    IOHandler = tidSMTP_SSL
    SASLMechanisms = <>
    UseTLS = utUseExplicitTLS
  end
  object tidSMTP_SSL: TIdSSLIOHandlerSocketOpenSSL
    Destination = 'smtp.gmail.com:587'
    Host = 'smtp.gmail.com'
    MaxLineAction = maException
    Port = 587
    DefaultPort = 0
    SSLOptions.Mode = sslmUnassigned
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0
  end

and Send button click event:

procedure TForm1.btnSendClick(Sender: TObject);
var
  mes:TIdMessage;
  fromAddress:TIdEmailAddressItem;
  toAddress:TIdEMailAddressItem;
begin
  tidSMTP.Username := txtUsername.Text;
  tidSMTP.Password := txtPassword.Text;
  tidSMTP.Host := txtSMTPserver.Text;           //smtp.gmail.com
  tidSMTP.Port := StrToInt(txtSMTPport.Text);   //587

  fromAddress := TIdEMailAddressItem.Create;
  fromAddress.Address := txtUsername.Text;

  toAddress := TIdEMailAddressItem.Create;
  toAddress.Address := txtTo.Text;

  mes := TIdMessage.Create;
  mes.ContentType := 'text/plain';
  mes.From := fromAddress;
  mes.ReceiptRecipient := toAddress;
  mes.Subject := txtSubject.Text;

  mes.Body := memoText.Lines;

  tidSMTP.Connect;
  tidSMTP.Send(mes);
  tidSMTP.Disconnect;
end;

Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

呆头 2024-11-07 23:01:09

将 SSL 方法设置为 SSL 版本 3 (tidSMTP_SSL.SSLOptions.Method)。我认为它默认为 SSL 版本 2,但 GMail 不支持它。

SSLOptions.Method := sslvSSLv3;

编辑:

您可以通过将事件处理程序分配给 IOHandler 的 OnStatusInfo 事件来记录 SSL 状态信息:

tidSMTP_SSL.OnStatusInfo := DoOnStatusInfo;

proceudre TForm1.DoOnStatusInfo(Msg: string);
begin
  // when running from IDE, message will appear in 
  // EventLog (Ctrl+Alt+V), otherwise, 
  // use DebugViewer.exe
  OutputDebugString(PChar(Msg)); 
end;

也许这会给您有关失败协商的线索。

PS:我使用的是 Indy 9.0.0.18,所以你的情况可能有所改变。

编辑2:

如果上述方法没有帮助,请检查是否有防火墙/防病毒软件阻止 smtp.gmail.com 或端口 587

Set you SSL Method to SSL version 3 (tidSMTP_SSL.SSLOptions.Method). I think it defaults to SSL version 2, but GMail does not support that.

SSLOptions.Method := sslvSSLv3;

Edit:

You can log the SSL Status info by assigning an eventhandler to the OnStatusInfo event of your IOHandler:

tidSMTP_SSL.OnStatusInfo := DoOnStatusInfo;

proceudre TForm1.DoOnStatusInfo(Msg: string);
begin
  // when running from IDE, message will appear in 
  // EventLog (Ctrl+Alt+V), otherwise, 
  // use DebugViewer.exe
  OutputDebugString(PChar(Msg)); 
end;

Maybe this will give you a clue about the failing negotation.

PS: I'm on Indy 9.0.0.18, so things may have changed for you.

Edit2:

If above does not help, please check if there is not a firewall / antivirus that is blocking smtp.gmail.com or port 587

绾颜 2024-11-07 23:01:09

我成功地让它像这样工作:

procedure TForm1.btn2Click(Sender: TObject);
var
  email      : TIdMessage;
  idSMTPGMail: TIdSMTP;
  idSSLGMail : TIdSSLIOHandlerSocketOpenSSL;
begin
  idSSLGMail                   := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  idSSLGMail.SSLOptions.Method := sslvTLSv1;
  idSSLGMail.SSLOptions.Mode   := sslmUnassigned;

  idSMTPGMail                  := TIdSMTP.Create(nil);
  idSMTPGMail.IOHandler        := idSSLGMail;
  idSMTPGMail.UseTLS           := utUseExplicitTLS;

  email                           := TIdMessage.Create(nil);
  email.From.Address              := txtUsername.Text;
  email.Recipients.EMailAddresses := txtTo.Text;
  email.Subject                   := txtSubject.Text;
  email.Body.Text                 := memoText.Text;

  idSMTPGMail.Host     := 'smtp.gmail.com';
  idSMTPGMail.Port     := 587;
  idSMTPGMail.UserName := txtUsername.Text;
  idSMTPGMail.Password := txtPassword.Text;

  idSMTPGMail.Connect;
  idSMTPGMail.Send(email);
  idSMTPGMail.Disconnect;

  email.Free;
  idSSLGMail.Free;
  idSMTPGMail.Free;
  Beep;
end;

我使用相同的 TEdit、TMemo,但动态创建 Indy 组件......

I successfully make it worked like this:

procedure TForm1.btn2Click(Sender: TObject);
var
  email      : TIdMessage;
  idSMTPGMail: TIdSMTP;
  idSSLGMail : TIdSSLIOHandlerSocketOpenSSL;
begin
  idSSLGMail                   := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  idSSLGMail.SSLOptions.Method := sslvTLSv1;
  idSSLGMail.SSLOptions.Mode   := sslmUnassigned;

  idSMTPGMail                  := TIdSMTP.Create(nil);
  idSMTPGMail.IOHandler        := idSSLGMail;
  idSMTPGMail.UseTLS           := utUseExplicitTLS;

  email                           := TIdMessage.Create(nil);
  email.From.Address              := txtUsername.Text;
  email.Recipients.EMailAddresses := txtTo.Text;
  email.Subject                   := txtSubject.Text;
  email.Body.Text                 := memoText.Text;

  idSMTPGMail.Host     := 'smtp.gmail.com';
  idSMTPGMail.Port     := 587;
  idSMTPGMail.UserName := txtUsername.Text;
  idSMTPGMail.Password := txtPassword.Text;

  idSMTPGMail.Connect;
  idSMTPGMail.Send(email);
  idSMTPGMail.Disconnect;

  email.Free;
  idSSLGMail.Free;
  idSMTPGMail.Free;
  Beep;
end;

I use the same TEdit, TMemo, but dynamically create the Indy components...

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