|
-
Aug 18th, 2004, 03:15 AM
#1
Thread Starter
Fanatic Member
Retrive mails from pop3 a/c
hi there,
can you plz guide me how to get the emails from a pop3 a/c using php codes???
-
Aug 18th, 2004, 07:41 AM
#2
This can be done in PHP . I would rate it about 7/10 in complexity. It involves opening a connection to the server and using the POP3 protocol to send commands to retireve the email.
The area where this can become beome very complex is in the authentication of the user. Fortunatly most POP3 servers use plain authentication and this does not pose a big problem.
A typical conversation with a POP3 server would look like this. You can do this in telnet with your own personal POP3 account:
Code:
C:\>telnet open post.myhost.com 110
+OK post.myhost.com Cyrus POP3 Murder v2.1.16-IPv6-Debian-2.1.16-0woodyFULLHASH
.3.7 server ready <[email protected]>
USER username
+OK Name is a valid mailbox
PASS password
+OK Maildrop locked and ready
STAT
+OK 1 252
RETR 1
+OK Message follows
Return-Path: <[email protected]>
Date: Wed, 18 Aug 2004 13:21:50 +0100
From: Random <[email protected]>
Message-ID: <[email protected]>
To: [email protected]
Subject: test
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
test data
.
DELE 1
QUIT
A quick explaination of what is going on. Similar to HTTP, POP3 is a pulling protocol (whereby the client requests the data from the server).
- First you connect on port 110 using telnet.
- You then send the USER command with the name of the user and the PASS command with the users password. If the server agrees with the credentials it will respond with a line starting "+OK".
- Once you have authenticated you send a STAT command. The server responds with a respons in the form "+OK n t" where n is the total number of messages in your mailbox and t is the total number of bytes for all the messages. You can obtain information on an individual message using the LIST comamnd.
- To downlaod the message you issue the RETR command followed by the message number. The server then dumps the entire email message terminated by a period "." on a line of its own.
- You can then delete the message from the mailbox by using the DELE command. This is typically what happens when your e-mail client picks up messages from the POP3 server.
- Finally you terminate the connection by sending the QUIT command.
To do this in PHP you'll need to use the fsockopen() function to establish the connection to the server and use normal file IO functions to send a recive data from the server. If I had the time I would provide some sample code, but for now I'll point you towards some info and tutorials:
Here is the POP3 RFC which is a complete specification of the protocol and all its commands: http://www.faqs.org/rfcs/rfc1939.html
PHP's IMAP functions are here. You need to ensure that you have enabled IMAP support before using them though. If you can use it then do becuase it makes things easier: http://uk2.php.net/imap
And here's a tutorial on building a PHP based mail client: http://www.devshed.com/c/a/PHP/Build...Client-part-1/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|