Results 1 to 2 of 2

Thread: Retrive mails from pop3 a/c

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Earth
    Posts
    762

    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???

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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).
    1. First you connect on port 110 using telnet.
    2. 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".
    3. 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.
    4. 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.
    5. 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.
    6. 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/
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width