|
Nowadays, most Web mail sites provide POP3 support, so you can retrieve your mailbox messages using PHP or any other language.
However, each system uses different ports and encryption configuration that you need to know in order to access them.
This article provides information on the details of accessing the messages on some of the most popular Web mail systems via POP 3.
It also provides a solution to a common problem, which is how to retrieve only the newly received messages when you never delete messages from the mailbox.
Contents
Gmail and Google App Accounts
Hotmail and Windows Live accounts
Yahoo! MailOther Web mail systems
Retrieving only the new unread messages
Processing retrieved e-mail messages
Gmail and Google App Accounts
Before retrieving messages from Gmail accounts, you need to enable POP support for your account. You can do that by going to the settings page, click on the tab named Forwarding and POP/IMAP, and enable one of the POP options that exposes the messages in your mailbox either since ever or only from now on.
Gmail POP3 server responds in the port 995 and it requires that you enable SSL/TLS encryption. The user name must be the account e-mail address including the domain part.
- $pop3 = new pop3_class;
- $pop3->hostname = "pop.gmail.com";
- $pop3->port = 995;
- $pop3->tls = 1;
- $user = "account@gmail.com";
- $password = "account password";
复制代码
Hotmail and Windows Live accounts
Accessing Hotmail accounts is similar to Gmail, except that it does not need to explicitly enable POP support in the Web interface.
- $pop3 = new pop3_class;
- $pop3->hostname = "pop3.live.com";
- $pop3->port = 995;
- $pop3->tls = 1;
- $user = "account@hotmail.com";
- $password = "account password";<b></b>
复制代码
Yahoo! Mail
Currently, accessing Yahoo! Mail mailbox messages via POP3 is restricted to paying users of the Yahoo! Mail plus service. Other than that, most parameters are similar to Gmail and Hotmail, except that the user name should be just the account user name, thus without the @ character and the domain name.
- $pop3 = new pop3_class;
- $pop3->hostname = "pop.mail.yahoo.com";
- $pop3->port = 995;
- $pop3->tls = 1;
- $user = "account";
- $password = "account password";
复制代码
Other Web mail systems
This article only covers a few of the most popular Web mail systems. If you know how to configure the POP3 access to other popular mail systems, please post a comment to this article, so you can share that information for benefit of other readers.
Retrieving only the new unread messages
Some applications retrieve e-mail messages from a mailbox via POP3 but do not delete the messages. Therefore they cannot easily determine if the message was already retrieved or is new.
Unfortunately, the POP3 protocol does not provide a way to determine which messages in a mailbox are new or were already retrieved in a previous access.
One way to solve this problem is to keep track of the message identifiers of the messages read so far, for instance storing those identifiers in a database.
The POP3 class ListMessage function can list all the messages if you pass an empty string as first parameter. If you pass the value 1 as second parameter, it will return an array with the unique identifier of all messages.
If you lookup your database of previously retrieved messages and compare with the unique identifiers of the messages in the POP3 mailbox, you can easily determine which messages are new by finding the unique identifiers of messages not present in your database.
This is not a very efficient solution if you have many messages in your mailbox, so it may take a while, but at least it is a solution that works when you retrieve messages via POP3.
Processing retrieved e-mail messages
Once you retrieve the new messages, you need to process them eventually parsing the messages to extract their information. That is a task that can be easily achieved using a separate PHP MIME message parser class in conjunction with the POP3 class.
That is a subject that was already covered in a past post of this blog about processing incoming mail messages using PHP.
If you have doubts or questions about how to achieve other purposes with this class that you would like to be covered in eventual posts of this blog, feel free to post a comment to this article.
POP3 e-mail client: Access to e-mail mailboxes using the POP3 protocol
Class that implements the access to mail boxes using the POP3 protocol.
It features:
- Support secure connections using TLS
- Provides a stream wrapper class to access messages like files using fopen('pop3://user:pass@localhost/1', 'r');
- POP3 server access using normal and apop login methods
- Authentication mechanisms implemented by SASL client class like: PLAIN, LOGIN, CRAM-MD5, NTLM (Windows or Linux/Unix via Samba), etc..
- Determining mailbox statistics (mail box size in bytes and the number of stored messages)
- Listing of individual message sizes and identifier numbers
- Retrieving messages in data blocks of limited size to not exceed the available memory
- Retrieving messages all at once separating the headers from the body and limiting the number of message lines that may be retrieved at once
- Marking messages to be deleted
- Resetting the list of messages to be deleted
- Issuing of protocol NOOP command to avoid connection shutdown while in idle state
Download .zip .tar.gz
|
|