Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Retrieving pop mail from gmail/ssl

621 views
Skip to first unread message

bill

unread,
May 28, 2009, 10:51:55 AM5/28/09
to
My ISP recently transferred its mail service to google, which
leaves me up a creek. I have an application that used to
retrieve pop3 using the IMAP package. Gmail uses POP over SSL on
port 995.

I changed my statement to:
$in=imap_open("{pop.gmail.com:995/pop3}","my@email_address.com",
"mu_password");

but, obviously this is inadequate as $in return bool(false).

Can I make this work ?

bill

Ok, for the wise among you - if I can make it work, how ?

"Álvaro G. Vicario"

unread,
May 28, 2009, 11:19:47 AM5/28/09
to
bill escribi�:

> My ISP recently transferred its mail service to google, which leaves me
> up a creek. I have an application that used to retrieve pop3 using the
> IMAP package. Gmail uses POP over SSL on port 995.
>
> I changed my statement to:
> $in=imap_open("{pop.gmail.com:995/pop3}","my@email_address.com",
> "mu_password");
>
> but, obviously this is inadequate as $in return bool(false).

I suppose you have to instruct imap_open() to use SSL. This is from
example #1 in the PHP manual:

// To connect to an SSL IMAP or POP3 server, add /ssl after the protocol
// specification:
$mbox = imap_open ("{localhost:993/imap/ssl}INBOX", "user_id", "password");

http://es.php.net/imap_open


--
-- http://alvaro.es - �lvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programaci�n web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

bill

unread,
May 29, 2009, 9:56:18 AM5/29/09
to
�lvaro G. Vicario wrote:
> bill escribi�:
>> My ISP recently transferred its mail service to google, which leaves
>> me up a creek. I have an application that used to retrieve pop3 using
>> the IMAP package. Gmail uses POP over SSL on port 995.
>>
>> I changed my statement to:
>> $in=imap_open("{pop.gmail.com:995/pop3}","my@email_address.com",
>> "mu_password");
>>
>> but, obviously this is inadequate as $in return bool(false).
>
> I suppose you have to instruct imap_open() to use SSL. This is from
> example #1 in the PHP manual:
>
> // To connect to an SSL IMAP or POP3 server, add /ssl after the protocol
> // specification:
> $mbox = imap_open ("{localhost:993/imap/ssl}INBOX", "user_id", "password");
>
> http://es.php.net/imap_open

Thanks for reading the manual for me, but it doesn't work.

After a long time (5 minutes ?) the script terminates with no
output.

here is my test script:
<?php

error_reporting(E_ALL);

echo "about to imap_open <br />";

$in=imap_open("{pop.gmail.com:995/pop3/ssl}","in...@xxxxxxxx.com",
"xxxxxxxxx");

echo "about to get headers - <br />";

$msgs=imap_headers($in); // gets the headers from the currently
available msgs

echo " <br />about to imap close <br />";
imap_close($in);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Test/Get Mail</title>
</head>
<body>
Test/Get Mail

</body>
</html>

if I comment out the imap_open statement it runs fine.


bill

unread,
May 29, 2009, 9:59:00 AM5/29/09
to
The server error log says:
> PHP Warning: imap_open(): Couldn't open stream {pop.gmail.com:995/pop3/ssl} in /hsphere/local/home/techservsys/houndsofheaven.com/ContactManagement/testGetMail.php on line 9

Anyone have any suggestions ?

Jerry Stuckle

unread,
May 29, 2009, 12:50:47 PM5/29/09
to

Is there an imap server running on port 995? The normal port for imap
over ssl is 993. Can you telnet into the port (preferably from that
server)?

What does the system log show?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

bill

unread,
May 30, 2009, 7:27:55 AM5/30/09
to

this is pop over ssl. And - this is gmail who does things their
own way frequently. I have it running just fine from
Thunderbird on port 995, but when I telnet in on that port
manually I get, "Connection to host lost"

On the other hand, when I telnet to pop.gmail.com on port 23 I
get, "Connect Failed"

The normal port for imap
> over ssl is 993. Can you telnet into the port (preferably from that
> server)?
>
> What does the system log show?

I don't think that google is going to let me access their server
logs.

bill

bill

unread,
May 30, 2009, 7:49:05 AM5/30/09
to

for fun and games I tried:

$in=imap_open("{imap.gmail.com:993/ssl}","in...@xxxxxxxx.com",
"xxxxxxxxx");
which hung

and telneted in to imap.gmail.com:993
which also hung.

when I type in a break, it replied, "connection to host lost," as
if it were waiting for something without having indicated that
the connection was established.

??

bill

>

The Natural Philosopher

unread,
May 30, 2009, 7:51:36 AM5/30/09
to
bill wrote:
> Jerry Stuckle wrote:
>> bill wrote:
>>> bill wrote:
>>>> Álvaro G. Vicario wrote:
>>>>> bill escribió:

I am not surprised. Standard pop is port 110, and SMTP mail is port 25.

Port 23 is the interactive remote login telnet service itself. I dont
think manual connection to an SSL service is ever going to work though.

You MIGHT be able to ssh to it however..try ssh pop.gmail.com -p995

Oh that doesn't work..

Looking at the manual

$in=imap_open("{pop.gmail.com:995/pop3/ssl}","in...@xxxxxxxx.com",
"xxxxxxxxx");

should work,

But here is a snippet from the php manual

"Works with Gmail's new IMAP function for personal and for Google Apps.

$mbox = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX",
"user...@gmail.com", "password")
or die("can't connect: " . imap_last_error());"

Also note that old PHP running on windows had a known bug

http://bugs.php.net/bug.php?id=36496


The complete manual page and comments are probably worth a thorough read.


The Natural Philosopher

unread,
May 30, 2009, 7:54:29 AM5/30/09
to
bill wrote:
> Jerry Stuckle wrote:
>> bill wrote:
>>> bill wrote:
>>>> Álvaro G. Vicario wrote:
>>>>> bill escribió:

Ah. here's a more useful snippet from the manual comments
>>>>
The following works for connecting via POP3 to a gmail server:
imap_open("{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX",
$username, $password);
<<<<
I cant test, cos have no gmail account.


Jerry Stuckle

unread,
May 30, 2009, 1:42:55 PM5/30/09
to

OK, just making sure - you're using 995 and 993 is pretty close; but
looking around, it seems port 995 is reserved for pop3 over ssl (I've
done the imap over ssl but not pop3).

It's been a while since I've looked at the low level stuff, but IIRC the
client is expected to initiate communications (passing an encryption
key? I don't remember for sure). If the server doesn't get acceptable
info, it drops the connection.

> On the other hand, when I telnet to pop.gmail.com on port 23 I get,
> "Connect Failed"
>

OK, so port 23 isn't open. But that's the telnet port, and I would
expect that wouldn't be open. I don't have it open on an of my servers,
either.

> The normal port for imap
>> over ssl is 993. Can you telnet into the port (preferably from that
>> server)?
>>
>> What does the system log show?
>
> I don't think that google is going to let me access their server logs.
>
> bill
>

Yep, I forgot you're using gmail.

Are you sure you have ssl support in PHP? Looks like it's missing, to me.

"Álvaro G. Vicario"

unread,
Jun 1, 2009, 3:28:01 AM6/1/09
to
bill escribi�:


I've tested your sample code with my Gmail account and it works fine as is.

I don't know if it'll be the case but you must consider two
peculiarities of their mail service:

1. You have to configure your Gmail account to allow POP3 download.
2. Unlike other mail services, Gmail's POP3 server downloads everything
you have, not just the INBOX. Perhaps so have so many messages that it
just times out.

bill

unread,
Jun 6, 2009, 3:59:15 PM6/6/09
to
The Natural Philosopher wrote:
> bill wrote:
>> Jerry Stuckle wrote:
>>> bill wrote:
>>>> bill wrote:
>>>>> ᅵlvaro G. Vicario wrote:
>>>>>> bill escribiᅵ:
Well, I tried this and the prior suggestion of using
imap.gmail.com:993

no joy.

If anyone wants to try these out, I would be willing to give them
access to a google account - write me privately:
william-ta...@TechServSys.put-in-a-com

bill

Jerry Stuckle

unread,
Jun 6, 2009, 11:22:38 PM6/6/09
to

But you never answered my other question - are you sure you have ssl
support in PHP?

--

bill

unread,
Jun 7, 2009, 9:37:03 AM6/7/09
to
it was configured
'--with-openssl=/usr'
'--with-imap=/usr'

and ssl is one of the Registered Stream Socket Transports
'--with-imap-ssl'

Jerry Stuckle

unread,
Jun 7, 2009, 10:04:04 AM6/7/09
to

Compiled and running are two different things. What does phpinfo() show?

bill

unread,
Jun 8, 2009, 6:54:53 AM6/8/09
to
imap
IMAP c-Client Version 2004
SSL Support enabled
Kerberos Support enabled

mlemos

unread,
Jun 10, 2009, 2:56:38 AM6/10/09
to
Hello,

I have no idea why IMAP extension functions are not working for you.
Anyway, I do not use that extension because I have a POP3 client class
that uses fsockopen function instead of the imap extension functions. It
works well for accessing Gmail messages using POP3.

http://www.phpclasses.org/pop3class

Take a look at the test_pop3.php example script. The comments tell you
how to setup the class to access specifcally Gmail.

The class also provides a nice feature that allows you to access
messages in POP3 servers as if they were files using regular PHP file
access functions and special URLs. For instance you can retrieve the
first message in your POP3 mailbox in Gmail with a single line of code:

$message =
file_get_contents('pop3://user:pass...@pop.gmail.com:995/1?tls=1');

BTW, if you want to parse the messages to extract their features, which
often you do, you can also use this MIME parser class together with POP3
class.

http://www.phpclases.org/mimeparser

This article tells you more on this:

http://www.phpclasses.org/blog/package/2/post/1-Process-incoming-email-messages-using-PHP.html


--

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

bill

unread,
Jun 13, 2009, 7:14:22 AM6/13/09
to
mlemos wrote:
> Hello,
>
> I have no idea why IMAP extension functions are not working for you.
> Anyway, I do not use that extension because I have a POP3 client class
> that uses fsockopen function instead of the imap extension functions. It
> works well for accessing Gmail messages using POP3.
>
> http://www.phpclasses.org/pop3class
>
> Take a look at the test_pop3.php example script. The comments tell you
> how to setup the class to access specifcally Gmail.
>
> The class also provides a nice feature that allows you to access
> messages in POP3 servers as if they were files using regular PHP file
> access functions and special URLs. For instance you can retrieve the
> first message in your POP3 mailbox in Gmail with a single line of code:
>
> $message =
> file_get_contents('pop3://user:pass...@pop.gmail.com:995/1?tls=1');
>
> BTW, if you want to parse the messages to extract their features, which
> often you do, you can also use this MIME parser class together with POP3
> class.
>
> http://www.phpclases.org/mimeparser
>
> This article tells you more on this:
>
> http://www.phpclasses.org/blog/package/2/post/1-Process-incoming-email-messages-using-PHP.html
>
>

No joy, at least your class returns the error message:
Error: 110 could not connect to the host "pop.gmail.com":
Connection timed out

bill

unread,
Jun 13, 2009, 7:40:11 AM6/13/09
to
...

>
> No joy, at least your class returns the error message:
> Error: 110 could not connect to the host "pop.gmail.com": Connection
> timed out

Further information:
I set:
$pop3->port=995;
$pop3->tls=1;
$apop=0;
$pop3->authentication_mechanism="USER";

Jerry Stuckle

unread,
Jun 13, 2009, 7:50:01 AM6/13/09
to

Not surprising.

bill

unread,
Jun 13, 2009, 10:50:08 AM6/13/09
to
agreed, but do YOU have any ideas on how to debug this ?

mlemos

unread,
Jun 13, 2009, 4:11:59 PM6/13/09
to
Hello,

on 06/13/2009 08:14 AM bill said the following:

That means your network is most likely blocking outgoing connections to
port 995, meaning there is a firewall in the way.

You need to ask your system administrator to unblock port 995 connections.

Jerry Stuckle

unread,
Jun 13, 2009, 4:43:27 PM6/13/09
to

Once he answers my questions...

The Natural Philosopher

unread,
Jun 13, 2009, 7:07:22 PM6/13/09
to
Weasel

Ive never seen you post a line of code here ever.

Jerry Stuckle

unread,
Jun 13, 2009, 9:36:00 PM6/13/09
to

That's because you can't read. We all know that.

You also have never posted an intelligent comment in this or any other
newsgroup. It seems you're quite famous in some circles - as a laughing
stock of usenet. I've gotten some good links to other posts of yours.
I also share links to your stoopid comments in this and other newsgroups
with the others.

You have quite a following. We get some great laughs.

And I don't see YOU posting anything *correct* in this thread, either.
If you're so smart, why haven't YOU fixed his problem for him?

The Natural Philosopher

unread,
Jun 14, 2009, 4:16:33 AM6/14/09
to
Because I dont know what the answer is.

Unlike you, I dont contribute unhelful pompous condescending suggestions
when I don't know the answer.


bill

unread,
Jun 14, 2009, 6:17:08 AM6/14/09
to
If you are referring to the questions about ssl support, they
were answered on 6/8
----------------------------

>
> Compiled and running are two different things. What does
phpinfo() show?
>
>
>
imap
IMAP c-Client Version 2004
SSL Support enabled
Kerberos Support enabled
-----------------------------------------------------
If you have other questions I would be glad to answer them.
bill

bill

unread,
Jun 14, 2009, 6:17:59 AM6/14/09
to
I have no problem retrieving the mail with Thunderbird on port 995.

Jerry Stuckle

unread,
Jun 14, 2009, 8:55:34 AM6/14/09
to

If you don't know the answer, you should keep your fat trap shut. Oh,
wait. Then you wouldn't be able to say ANYTHING, would you? Because
you don't know anything.

No wonder you hide behind an alias. If I were such a fool, I wouldn't
want people to know my real name, either. Especially if it were my boss.

Jerry Stuckle

unread,
Jun 14, 2009, 9:17:43 AM6/14/09
to

Sorry, I missed your message.

OK, it shows IMAP support for SSL is enabled. But what about SSL
itself? What version of SSL do you have installed on your system?

You should see mod_ssl in your loaded modules; you should also see other
entries for your SSL package (probably OpenSSL) in your environment.
And if you're running this under a web server, you should see the
information in your web server setup section.

mlemos

unread,
Jun 14, 2009, 5:18:32 PM6/14/09
to
Hello,

on 06/14/2009 07:17 AM bill said the following:

But is Thunderbird running on the same machine on which you are trying
to access Gmail POP3 using PHP?

If so, are you running Windows? If so, could you have authorized
Thunderbird to access Gmail but not PHP?

Another thing, are you sure you set the tls variable to 1, so the POP3
class uses tls to establish the connection?

bill

unread,
Jun 15, 2009, 10:10:28 AM6/15/09
to

openssl
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8b 04 May 2006

Anything else you want to know ?
http://www.houndsofheaven.com/ContactManagement/phpinfo.php

bill

unread,
Jun 15, 2009, 10:12:28 AM6/15/09
to

ah, good point. The script is running on a commercial shared
server - I will check with them.


>
> Another thing, are you sure you set the tls variable to 1, so the POP3
> class uses tls to establish the connection?

I am sure.

more when I get the reply back from the provider.
>

Jerry Stuckle

unread,
Jun 15, 2009, 12:15:22 PM6/15/09
to

OK, I set up a test gmail account and tried your code - it worked
perfectly, showing (correctly) no mail in my box.

The next thing to try is to ensure you have access to gmail port 995
from the system you're running the script on. Can you telnet from the
server to pop.gmail.com port 995? You won't be able to do the
handshaking, but it's important to know if it can connect.

bill

unread,
Jun 16, 2009, 5:57:53 AM6/16/09
to

working on validating the connectivity - have to wait for the
unbelievably slow tech support people at the host.

more to follow,
thanks

Jerry Stuckle

unread,
Jun 16, 2009, 6:37:22 AM6/16/09
to

So you have telnet or ssh access to the system? If so, you should be
able to telnet from there.

BTW - if their tech support is this slow, I'd recommend a new hosting
company. IMHO, non-critical requests should be answered within 2-4
hours max.

bill

unread,
Jun 17, 2009, 7:24:14 AM6/17/09
to
I fully agree with you and will be moving when my contract
expires - maybe sooner !

They confirmed that they have blocked port 995 outgoing for no
apparent reason but they are willing to unblock it (when they get
around to it) for one IP address. Wowie.

Stay tuned and thanks.

bill

bill

unread,
Jun 17, 2009, 7:25:09 AM6/17/09
to
Yup, The hosting provider has it blocked.
They are releasing it - someday.
Thanks

bill

Jerry Stuckle

unread,
Jun 17, 2009, 11:00:23 AM6/17/09
to

I guess I can understand that. Good hosts will block unnecessary ports
for security reasons. The fact they are willing to unblock it for you
is a definite plus.

0 new messages