Recover GMail Mailbox with Indy 10

I am trying to create an application with Delphi, you have to read incoming Gmail messages and have to process emails for special purposes.

I built this application using Indy POP3 components, part of the code below.

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;

Doesn't work, answer "bad team"

+4
source share
1 answer

"Ok Google!"

Tested with Indy 10.6.2.5298 and OpenSSL 1.0.2h, Delphi DX10 (not update 1)

1) This line looks optional. Why are you going to name the component that was created during development?

Name := 'POP3';

2) Try to login after connecting

POP3.Connect;
POP3.Login;

3) , EIdReplyPOP3Error with message 'Web login required: https://support.google.com/mail/answer/78754, , application specific password Allow less secure apps Gmail

enter image description here

0

All Articles