Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (8)


Accessing GMail account with IndyFormat this article printer-friendly!Bookmark function is only available for registered users!
How access POP3 ssl accounts with Delphi
Product:
Delphi 5.x (or higher)
Category:
Internet / Web
Skill Level:
Scoring:
Last Update:
06/20/2005
Search Keys:
delphi delphi3000 article borland vcl code-snippet gmail indy pop3 ssl
Times Scored:
43
Visits:
22443
Uploader: Radikal Q3
Company: Q3
Reference: q3.nu/trucomania
 
Question/Problem/Abstract:
Access GMail accounts vía POP3 SSL
Answer:



GMail is the free mail service of Google.
Recently, the GMail accounts can also be accessed by means of POP3 and SMTP protocols (that is to say, to use them through a mail client program like OutLook)
It has a peculiarity, the access to GMail through POP3 uses encriptación SSL and No-Standard ports.
This tip explains briefly how to connect with POP3 service of GMail through the Indy components.

You need to put in one form these components:


  • A TidPop3 (idPop31) (Indy Clients Tab)

  • A TidMessage (idMessage1) (Indy Misc Tab)

  • A TIdSSLIOHandlerSocket (IdSSLIOHandlerSocket1) (Indy I/O handlers Tab)

  • A TMemo (Memo1)

  • A TButton (Button1)

  
    
So that the SSL works, the Indy uses the OpenSSL library, that is GPL and that another people do, for that reason, you have to download it so that the TIdSSLIOHandlerSocket can use it.

I for this test, have downloaded it of:  http://indy.fulgan.com/SSL/and the file that I have used is indy_openssl096.zip

Descompress the the ZIP and put the two DLLs in the directory of your project.

Now, make that idPop31 uses the IdSSLIOHandlerSocket1 putting it in its IOHandler property.

Set the name of the pop server in the Host property of idPop31, that in the case of Gmail is pop.gmail.com, set the port, that in this case is special and is 995 and set the username and your password in the idPop31 component.


Once made, to test the invention, put this code in the OnCLick de Button1:

procedure TForm1.Button1Click(Sender: TObject);
var
  n,
  nummsgs    : integer;
begin
  Memo1.Lines.Clear;
  //Conectamos!
  idpop31.Connect(0);

  //Obtenemos el numero de emails que tenemos
  NumMsgs:=idpop31.CheckMessages;

  Memo1.lines.add( 'Emails:' +IntToStr(NumMsgs) );

  for n:=1 to NumMsgs do begin
    idpop31.RetrieveHeader(n,idMessage1);
    Memo1.Lines.Add( 'Email Nº:'+IntToStr(n)+
                     ' De:'+idMessage1.From.Text+
                     ' Tema:'+idMessage1.Subject );
    idMessage1.Clear;
  end;
  idpop31.Disconnect;
end;

and you will have an example that will obtain the headers of the emails of GMail account.

NOTE: Yo need an actual version of the Indy library. If your Delphi hasn't, dont worry, you can download it from the oficcial website: http://www.indyproject.org/





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
not working !
    ryan ryan (Jun 7 2006 8:05AM)

i've tried this and the application went stalled then after awhile an error msg appeared it says connection closed gracefully. and the message didn't show on the memo box.
pls help...
Respond

RE: not working !
aiirii michael (Aug 9 2006 5:01PM)

me too!
same error!
Respond

RE: not working !
Al Lindsay (Nov 19 2006 5:12PM)

same error here, until.....
I set the useTLS property of idpop31 to utUseImplicitTLS.



Respond

RE: RE: not working !
Joe Hé (Sep 29 2007 10:40PM)

I don't have TLS property of idpop31 ... (Indy 9.00.10)

Respond

How about an Indy 9.0.18 Example
    Jayme Jeffman (Sep 14 2005 7:37PM)

I was searching for an Indy 9.0.18 example on connecting to the Gmail SMTP server which requires authentication portable to the C++Builder6.0 environment.
Respond

RE: How about an Indy 9.0.18 Example
qingchong cai (Mar 8 2006 5:46AM)

thank! I need the example.
Respond

RE: RE: How about an Indy 9.0.18 Example
Jay Cee (Oct 21 2007 11:58AM)

When I tried this, I ran my app and found that the first check for GMail returned an exception and no emails (even tho there were emails waiting) and any second, third, fourth etc checks worked fine.

When the app was closed, and restarted the same problem occurred.

As a quick fix I had to find a way of determining whether the app was making a call to an SSL account for the first time or not. If it WAS, then I had to connect, disconnect and connect again BEFORE checking for any messages, and everything worked fine.

I'm new to the SSL implementation so perhaps someone who knows better can shed light on this and provide a better way.

The boolean (firsttimeSSL) remembers whether the app has already tried to connect to an SLL account or not. It should be set to TRUE at the start of your app.

Sample:

      oPop3 := TidPOP3.Create(MainForm);
      oPOP3.ReadTimeout := 15000;
      oPOP3.Host := THE SERVER;
      oPOP3.Port := THE PORT;
      oPOP3.Username := THE USER NAME;
      oPOP3.Password := THE PASSWORD;

      If connect_using_ssl Then Begin
         { I/O handling for SSL (google gmail etc) }
         IO := TIdSSLIOHandlerSocketOpenSSL.Create(MainForm);
         IO.MaxLineAction := maSplit;  //maException;
         IO.ConnectTimeout := 15000;
         IO.SSLOptions.Method := sslvSSLv2; //sslvSSLv23;
         IO.SSLOptions.Mode := sslmUnassigned; //sslmClient;
         IO.SSLOptions.VerifyMode := [];
         IO.SSLOptions.VerifyDepth := 0;
         opop3.IOHandler := IO;
         opop3.UseTLS := utUseImplicitTLS;
         IO.Host := THE SERVER ;
         IO.Port := THE PORT;
      End
     Else
      Begin
         oPOP3.IOHandler := nil;
         oPOP3.UseTLS := utNoTLSSupport;
      End;

      Try
         oPop3.Connect;
      Except
         If (connect_using_ssl) And (firsttimeSSL) Then Begin
            firsttimeSSL := False;
            Try
               If oPOP3.Connected then oPOP3.Disconnect;
        
Respond

RE: RE: RE: How about an Indy 9.0.18 Example
rudyno nasrial (Sep 25 2009 12:53PM)

I can receive the email with the coding, but I can only see the sender address and the subject email, but i cannot see the messages..
I already add this code line:
Memo1.Lines.Add( 'Email Nº:'+IntToStr(n)+
                     ' De:'+idMessage1.From.Text+
                     ' Tema:'+idMessage1.Subject+' Isi Pesan:'+idMessage1.Body.Text);

Any suggestion
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
C.A. Longen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)