Delphi Indy GMail安全问题

时间:2015-04-16 16:06:01

标签: delphi email gmail indy

我已使用以下代码使用GMail的SMTP服务器成功发送了电子邮件。我使用的是Delphi 2006和最新版本的Indy(10.6.2)以及最新的fulgan ssl库。问题是我必须按照Google链接中的说明拒绝GMail安全设置。使用默认的高设置,我会收到类似这样的神秘错误:" https://accounts.google.com/ContinueSignIn?[...]请通过网络浏览器登录,然后重试。在https://support.google.com/mail/bin/answer.py?answer=78754 [...] - gsmtp"了解详情。如何调整以下代码以使用GMail的高安全性设置?

  IdSMTP1.host:='smtp.gmail.com';
  IdSMTP1.username:='[deleted]@gmail.com';
  IdSMTP1.Password:='[deleted]';
  IdSMTP1.port:=587;
  IdSMTP1.UseTLS:=utUseExplicitTLS;
  IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmClient;
  IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method:= sslvTLSv1;
  IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth := 2;
  IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyMode := [];
  IdSSLIOHandlerSocketOpenSSL1.Host := IdSMTP1.Host;
  IdSSLIOHandlerSocketOpenSSL1.Port := IdSMTP1.Port;

  IdMessage1.From.address := '[deleted]@gmail.com';
  IdMessage1.CClist.EMailAddresses:= edit1.Text;
  IdMessage1.Subject:= 'Subject is here';
  IdMessage1.Body.Clear;
  Idmessage1.Body.Add('Body is here');
  IdSMTP1.Connect;
  try
    try
      idSMTP1.Send(IdMessage1);
    except on E:Exception do
      Memo1.Lines.Insert(0, 'ERROR: ' + E.Message);
    end;
  finally
    if idSMTP1.Connected then idSMTP1.Disconnect;
  end;

0 个答案:

没有答案