【问题标题】:Retrieve GMail inbox with Indy 10使用 Indy 10 检索 GMail 收件箱
【发布时间】:2016-09-12 22:55:16
【问题描述】:

我正在尝试使用 Delphi 构建一个应用程序,您必须阅读 Gmail 收件箱,并且必须为特殊目的处理电子邮件。

我使用 Indy 组件 POP3 构建了这个应用程序,部分代码如下。

procedure TfrmMain.LeerCorreos;
var
  mensaje: TIdMessage;
  i: Integer;
begin
  try
    with POP3 do
    begin
      Name := 'POP3';
      AutoLogin := False;
      Host := 'pop.gmail.com';
      Username := '*******@gmail.com';
      Password := '*****';
      Port := 995;
      IOHandler := IdSSLIOHandlerSocketOpenSSL;
      UseTLS := utUseImplicitTLS;
    end;
    with IdSSLIOHandlerSocketOpenSSL do
    begin
      Destination := 'pop.gmail.com:995';
      Host := 'pop.gmail.com';
      Port := 995;
      DefaultPort := 0;
    end;
    POP3.Connect;
    try
      Mensajes.Clear;
      mensaje := TIdMessage.Create(nil);
      try
        for i := 1 to POP3.CheckMessages do
        begin
          mensaje.Clear;
          POP3.RetrieveHeader(i, mensaje);
          Mensajes.Items.Add;
          Mensajes.Items[i - 1].SubItems.Add(mensaje.From.Address);
          Mensajes.Items[i - 1].SubItems.Add(mensaje.Subject);
          Mensajes.Items[i - 1].SubItems.Add(DateToStr(mensaje.Date));
        end;
      finally
        FreeAndNil(mensaje);
      end;
    finally
      POP3.Disconnect;
    end;
  except
    on e : Exception do
      ShowMessage('error=' + e.Message);
  end;
end;

不行,回复“bad command”

【问题讨论】:

  • 太棒了.... POP3.Login 工作。谢谢。

标签: delphi ssl indy pop3


【解决方案1】:

“好的谷歌!”

使用 Indy 10.6.2.5298 和 OpenSSL 1.0.2h、Delphi DX10(不是更新 1)测试

1) 这行看起来不需要。为什么要将名称设置为在设计时创建的组件?

Name := 'POP3';

2) 连接后尝试登录

POP3.Connect;
POP3.Login;

3) 如果您收到EIdReplyPOP3Error with message 'Web login required: https://support.google.com/mail/answer/78754 之类的错误,可能您必须使用application specific password 或在Gmail 设置中打开Allow less secure apps

【讨论】:

  • @MiguelMolina:TIdPOP3.AutoLogin 默认为 True。如果为 True,TIdPOP3.Connect() 会自动为您调用 TIdPOP3.Login()。由于您将TIdPOP3.AutoLogin 设置为False,因此您必须手动调用TIdPOP3.Login()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-01
  • 2014-12-19
  • 2011-05-30
  • 1970-01-01
  • 2015-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多