eustachio
eustachio

Reputation: 89

Delphi: connection IMAP to gmail account

I try to connect me to a test gmail account. I had activated IMAP, stopped my local firewall and antivirus.

I am using 2 Indy components:

imap: TIdIMAP4; ssl: TIdSSLIOHandlerSocketOpenSSL;

and I do

imap.Connect();

It connects but disconnect shortly after.

Here the project (Delphi XE3) with included user and psw to gmail test account.

http://sqlmis.com/update/testimap.zip

I tried different options in TIdSSLIOHandlerSocketOpenSSL components and in TIdIMAP4 but with no success.

The credentials are:

host=imap.gmail.com
[email protected]

and the 2 indy components are:

object ssl: TIdSSLIOHandlerSocketOpenSSL
    OnStatus = sslStatus
    Destination = 'imap.gmail.com:993'
    Host = 'imap.gmail.com'
    MaxLineAction = maException
    Port = 993
    DefaultPort = 0
    SSLOptions.Method = sslvSSLv23
    SSLOptions.SSLVersions = [sslvSSLv3, sslvTLSv1]
    SSLOptions.Mode = sslmUnassigned
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0

object imap: TIdIMAP4
    OnStatus = imapStatus
    IOHandler = ssl
    OnDisconnected = imapDisconnected
    OnConnected = imapConnected
    Password = 'fudbafqpmjgikxct'
    Port = 993
    Username = '[email protected]'
    Host = 'imap.gmail.com'
    UseTLS = utUseImplicitTLS
    SASLMechanisms = <>
    MilliSecsToWaitToClearBuffer = 10

Thanks a lot for any help or suggestion

Peter

P.S.: here the log of the imap and ssl components

SSL Status = Resolving hostname imap.gmail.com.
SSL Status = Connecting to 64.233.167.108.
SSL Info = SSL status: "before/connect initialization"
SSL Info = SSL status: "before/connect initialization"
SSL Info = SSL status: "SSLv2/v3 write client hello A"
SSL Info = SSL status: "SSLv3 read server hello A"
SSL Info = SSL status: "SSLv3 read server certificate A"
SSL Info = SSL status: "SSLv3 read server key exchange A"
SSL Info = SSL status: "SSLv3 read server done A"
SSL Info = SSL status: "SSLv3 write client key exchange A"
SSL Info = SSL status: "SSLv3 write change cipher spec A"
SSL Info = SSL status: "SSLv3 write finished A"
SSL Info = SSL status: "SSLv3 flush data"
SSL Info = SSL status: "SSLv3 read server session ticket A"
SSL Info = SSL status: "SSLv3 read finished A"
SSL Info = SSL status: "SSL negotiation finished successfully"
SSL Info = SSL status: "SSL negotiation finished successfully"
SSL Info = Cipher: name = ECDHE-RSA-RC4-SHA; description = ECDHE-RSA-RC4-SHA       SSLv3 Kx=ECDH     Au=RSA  Enc=RC4(128)  Mac=SHA1
; bits = 128; version = TLSv1/SSLv3; 
Status = Connected.
IMAP Connected SUCCESS
Status = Disconnecting.
IMAP DISCONNECTED
Status = Disconnected.

Here the complete Unit code:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdComponent, IdIOHandler,

  IdException,

  IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdIMAP4, IdMessage,
  IdBaseComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
  IdMessageClient, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    mess: TIdMessage;
    imap: TIdIMAP4;
    ssl: TIdSSLIOHandlerSocketOpenSSL;
    mLog: TMemo;
    Button1: TButton;
    lbFolder: TListBox;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure imapConnected(Sender: TObject);
    procedure imapDisconnected(Sender: TObject);
    procedure imapStatus(ASender: TObject; const AStatus: TIdStatus;
      const AStatusText: string);
    procedure sslStatus(ASender: TObject; const AStatus: TIdStatus;
      const AStatusText: string);
    procedure sslStatusInfo(const AMsg: string);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
    sender_mail, sender_name, uid : string;
begin
imap.Connect();
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
imap.ListMailBoxes(lbFolder.Items);
end;

procedure TForm1.imapConnected(Sender: TObject);
begin
mLog.Lines.Add('IMAP Connected SUCCESS');
end;

procedure TForm1.imapDisconnected(Sender: TObject);
begin
mLog.Lines.Add('IMAP DISCONNECTED');
end;

procedure TForm1.imapStatus(ASender: TObject; const AStatus: TIdStatus;
  const AStatusText: string);
begin
mLog.Lines.Add('Status = ' + AStatusText);
end;

procedure TForm1.sslStatus(ASender: TObject; const AStatus: TIdStatus;
  const AStatusText: string);
begin
mLog.Lines.Add('SSL Status = ' + AStatusText);
end;

procedure TForm1.sslStatusInfo(const AMsg: string);
begin
mLog.Lines.Add('SSL Info = ' + AMsg);
end;

end.

Upvotes: 2

Views: 2693

Answers (1)

eustachio
eustachio

Reputation: 89

I used so much time for this imap connection, tried with other components, and at the end,.. by rechecking again, the connection credentials was wrong (one character wrong). Now it work's. Many sorry for the disturb Peter

Upvotes: 1

Related Questions