gpt4 book ai didi

delphi - 向 Gmail 发送消息失败,错误为 "Start SSL negotiation command failed."

转载 作者:行者123 更新时间:2023-12-03 15:51:06 28 4
gpt4 key购买 nike

找到了我遵循的提示 here .

我在 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;

如有任何帮助,我们将不胜感激!

最佳答案

将 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

关于delphi - 向 Gmail 发送消息失败,错误为 "Start SSL negotiation command failed.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5618310/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com