向gmail发送消息失败,并显示“启动SSL协商命令失败。”错误 [英] Sending message to gmail fails with "Start SSL negotiation command failed." error
问题描述
我跟踪的提示此处。
我在win32文件夹中有libeay32.dll和ssleay32.dll。
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 = sslmUAssigned
SSLOptions.VerifyMode = []
SSLOptions.VerifyDepth = 0
结束
和发送按钮点击事件:
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;
编辑:
tidSMTP_SSL.OnStatusInfo:您可以通过将事件处理程序分配给IOHandler的OnStatusInfo事件来记录SSL状态信息: = DoOnStatusInfo;
procedure TForm1.DoOnStatusInfo(Msg:string);
begin
//当从IDE运行时,消息将出现在
// EventLog(Ctrl + Alt + V)中,否则
//使用DebugViewer.exe
OutputDebugString(PChar(Msg));
end;
也许这会给你一个关于失败谈判的线索。
PS:我在Indy 9.0.0.18上,所以事情可能已经改变了。
Edit2:
如果上述内容无效,请检查是否没有阻止smtp.gmail.com或端口587的防火墙/防病毒软件。
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!
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
这篇关于向gmail发送消息失败,并显示“启动SSL协商命令失败。”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!