我想用delphi发送一些电子邮件,我有这个小代码:
procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
IdMsgSend := TIdMessage.Create(nil);
SSLHandler :=TIdSSLIOHandlerSocketOpenSSL.Create(nil);
try
with IdMsgSend do
begin
ContentType := 'text/plain';
Body.Text := 'Test test text';
From.Text := 'USERNAME@gmail.com';
ReplyTo.EMailAddresses := 'Recipient@server.com';
Recipients.EMailAddresses := 'Recipient@server.com';
Subject := 'i just came to say hello';
end;
SMTP := TIdSMTP.Create(nil);
try
SMTP.Username := 'USERNAME@gmail.com';
SMTP.Password := 'PASSWODD';
SMTP.Host := 'smtp.gmail.com';
SMTP.Port := 465;
SMTP.IOHandler := SSLHandler;
SSLHandler.SSLOptions.Method := sslvSSLv3;
SMTP.UseTLS := utUseExplicitTLS;
SMTP.Connect;
try
IdMsgSend.Body.Text := 'The body';
IdMsgSend.Subject := 'The subject';
SMTP.Send(IdMsgSend);
finally
SMTP.Disconnect;
end;
finally
FreeAndNil(SMTP);
end;
finally
FreeAndNil(IdMsgSend);
end;
end;
以前工作得很好!现在,每当我尝试发送电子邮件时,我都会在SMTP.Send(IdMsgSend)
收到此错误:
连接正常关闭
我读过它可能来自防病毒或防火墙,所以我禁用它们,但仍然是同样的问题?
这里有什么问题? gmail改变了它的SMTP选项或类似的东西吗?