有人可以告訴我我做錯了什么(或沒有做)嗎?
這是我的程式代碼:
procedure TForm20.SendImage(const Comment, AImage: String);
var
SMTP: TIdSMTP;
Msg: TIdMessage;
begin
Msg := TIdMessage.Create(nil);
try
Msg.From.Address := '[email protected]';
Msg.Recipients.EMailAddresses := '[email protected]';
Msg.Body.Text := 'hello dennis';
Msg.Subject := 'free space';
SMTP := TIdSMTP.Create(nil);
try
SMTP.Host := 'smtp.gmail.com';
SMTP.Port := 587;
//SMTP.Port := 465; //gives different error-connection closed gracefully but
//no email is sent or received
SMTP.AuthType := satDefault;
SMTP.Username := '[email protected]';
SMTP.Password := '$$$$$$$';
SMTP.Connect;
//fails with port 25- connection time out socket error
//with port 465 it never gets past smtp connect. shows 'closed graceflly'
//with port 587 it gets past connect but then says
//'must issue a STARTTLS command first' before smtp.send(msg)
SMTP.Send(Msg);
finally
SMTP.Free;
end;
finally
Msg.Free;
end;
end;
uj5u.com熱心網友回復:
問題是您沒有設定TIdSMTP.UseTLS屬性。
在埠 25 和 587 上,您必須設定UseTLS為utUseExplicitTLS,然后TIdSMTP將發出STARTTLS命令以在發送電子郵件之前啟動 SSL/TLS 握手。
在埠 465 上,您必須設定UseTLS為utUseImplicitTLS,然后TIdSMTP將在連接后立即啟動 SSL/TLS 握手,然后再讀取服務器的問候語。
無論哪種方式,使用 SSL/TLS 都需要在連接到服務器之前為屬性分配一個TIdSSLIOHandlerSocketBase衍生組件,例如,例如:TIdSSLIOHandlerSocketOpenSSLTIdSMTP.IOHandler
var
IO: TIdSSLIOHandlerSocketOpenSSL;
...
IO := TIdSSLIOHandlerSocketOpenSSL.Create(SMTP);
IO.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
// configure other IO properties as needed...
SMTP.IOHandler := IO;
注意TIdSSLIOHandlerSocketOpenSSL不支持 TLS 1.3 。此時,如果您需要使用 TLS 1.3 ,請為此目的嘗試此作業中的 SSLIOHandler。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/424537.html
上一篇:針對常量整數集的案例陳述?
