{
    "mode": "perldoc",
    "parameter": "Mail::POP3Client",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3APOP3Client/json",
    "generated": "2026-06-13T07:35:20Z",
    "synopsis": "use Mail::POP3Client;\n$pop = new Mail::POP3Client( USER     => \"me\",\nPASSWORD => \"mypassword\",\nHOST     => \"pop3.do.main\" );\nfor( $i = 1; $i <= $pop->Count(); $i++ ) {\nforeach( $pop->Head( $i ) ) {\n/^(From|Subject):\\s+/i && print $, \"\\n\";\n}\n}\n$pop->Close();\n# OR with SSL\n$pop = new Mail::POP3Client( USER     => \"me\",\nPASSWORD => \"mypassword\",\nHOST     => \"pop3.do.main\",\nUSESSL   => true,\n);\n# OR\n$pop2 = new Mail::POP3Client( HOST  => \"pop3.otherdo.main\" );\n$pop2->User( \"somebody\" );\n$pop2->Pass( \"doublesecret\" );\n$pop2->Connect() >= 0 || die $pop2->Message();\n$pop2->Close();\n# OR to use your own SSL socket...\nmy $socket = IO::Socket::SSL->new( PeerAddr => 'pop.securedo.main',\nPeerPort => 993,\nProto    => 'tcp') || die \"No socket!\";\nmy $pop = Mail::POP3Client->new();\n$pop->User('somebody');\n$pop->Pass('doublesecret');\n$pop->Socket($socket);\n$pop->Connect();",
    "sections": {
        "NAME": {
            "content": "Mail::POP3Client - Perl 5 module to talk to a POP3 (RFC1939) server\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Mail::POP3Client;\n$pop = new Mail::POP3Client( USER     => \"me\",\nPASSWORD => \"mypassword\",\nHOST     => \"pop3.do.main\" );\nfor( $i = 1; $i <= $pop->Count(); $i++ ) {\nforeach( $pop->Head( $i ) ) {\n/^(From|Subject):\\s+/i && print $, \"\\n\";\n}\n}\n$pop->Close();\n\n# OR with SSL\n$pop = new Mail::POP3Client( USER     => \"me\",\nPASSWORD => \"mypassword\",\nHOST     => \"pop3.do.main\",\nUSESSL   => true,\n);\n\n# OR\n$pop2 = new Mail::POP3Client( HOST  => \"pop3.otherdo.main\" );\n$pop2->User( \"somebody\" );\n$pop2->Pass( \"doublesecret\" );\n$pop2->Connect() >= 0 || die $pop2->Message();\n$pop2->Close();\n\n# OR to use your own SSL socket...\nmy $socket = IO::Socket::SSL->new( PeerAddr => 'pop.securedo.main',\nPeerPort => 993,\nProto    => 'tcp') || die \"No socket!\";\nmy $pop = Mail::POP3Client->new();\n$pop->User('somebody');\n$pop->Pass('doublesecret');\n$pop->Socket($socket);\n$pop->Connect();\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module implements an Object-Oriented interface to a POP3 server. It implements RFC1939\n(http://www.faqs.org/rfcs/rfc1939.html)\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Here is a simple example to list out the From: and Subject: headers in your remote mailbox:\n\n#!/usr/local/bin/perl\n\nuse Mail::POP3Client;\n\n$pop = new Mail::POP3Client( USER     => \"me\",\nPASSWORD => \"mypassword\",\nHOST     => \"pop3.do.main\" );\nfor ($i = 1; $i <= $pop->Count(); $i++) {\nforeach ( $pop->Head( $i ) ) {\n/^(From|Subject):\\s+/i and print $, \"\\n\";\n}\nprint \"\\n\";\n}\n",
            "subsections": []
        },
        "CONSTRUCTORS": {
            "content": "Old style (deprecated): new Mail::POP3Client( USER, PASSWORD [, HOST, PORT, DEBUG, AUTHMODE] );\n\nNew style (shown with defaults): new Mail::POP3Client( USER => \"\", PASSWORD => \"\", HOST =>\n\"pop3\", PORT => 110, AUTHMODE => 'BEST', DEBUG => 0, TIMEOUT => 60, LOCALADDR =>\n'xxx.xxx.xxx.xxx[:xx]', SOCKET => undef, USESSL => 0, );\n\n*   USER is the userID of the account on the POP server\n\n*   PASSWORD is the cleartext password for the userID\n\n*   HOST is the POP server name or IP address (default = 'pop3')\n\n*   PORT is the POP server port (default = 110)\n\n*   DEBUG - any non-null, non-zero value turns on debugging (default = 0)\n\n*   AUTHMODE - pass 'APOP' to force APOP (MD5) authorization. (default is 'BEST')\n\n*   TIMEOUT - set a timeout value for socket operations (default = 60)\n\n*   LOCALADDR - allow selecting a local inet address to use\n",
            "subsections": []
        },
        "METHODS": {
            "content": "These commands are intended to make writing a POP3 client easier. They do not necessarily map\ndirectly to POP3 commands defined in RFC1081 or RFC1939, although all commands should be\nsupported. Some commands return multiple lines as an array in an array context.\n\n*new*( USER => 'user', PASSWORD => 'password', HOST => 'host', PORT => 110, DEBUG => 0,\nAUTHMODE => 'BEST', TIMEOUT => 60,, LOCALADDR => 'xxx.xxx.xxx.xxx[:xx]', SOCKET => undef,\nUSESSL => 0 ) )\nConstruct a new POP3 connection with this. You should use the hash-style constructor.\nThe old positional constructor is deprecated and will be removed in a future release. It\nis strongly recommended that you convert your code to the new version.\n\nYou should give it at least 2 arguments: USER and PASSWORD. The default HOST is 'pop3'\nwhich may or may not work for you. You can specify a different PORT (be careful here).\n\nnew will attempt to Connect to and Login to the POP3 server if you supply a USER and\nPASSWORD. If you do not supply them in the constructor, you will need to call Connect\nyourself.\n\nThe valid values for AUTHMODE are 'BEST', 'PASS', 'APOP' and 'CRAM-MD5'. BEST says to\ntry APOP if the server appears to support it and it can be used to successfully log on,\nnext try similarly with CRAM-MD5, and finally revert to PASS. APOP and CRAM-MD5 imply\nthat an MD5 checksum will be used instead of sending your password in cleartext.\nHowever, if the server does not claim to support APOP or CRAM-MD5, the cleartext method\nwill be used. Be careful. There are a few servers that will send a timestamp in the\nbanner greeting, but APOP will not work with them (for instance if the server does not\nknow your password in cleartext). If you think your authentication information is\ncorrect, run in DEBUG mode and look for errors regarding authorization. If so, then you\nmay have to use 'PASS' for that server. The same applies to CRAM-MD5, too.\n\nIf you enable debugging with DEBUG => 1, socket traffic will be echoed to STDERR.\n\nAnother warning, it's impossible to differentiate between a timeout and a failure.\n\nIf you pass a true value for USESSL, the port will be changed to 995 if it is not set or\nis 110. Otherwise, it will use your port. If USESSL is true, IO::Socket::SSL will be\nloaded. If it is not in your perl, the call to connect will fail.\n\nnew returns a valid Mail::POP3Client object in all cases. To test for a connection\nfailure, you will need to check the number of messages: -1 indicates a connection error.\nThis will likely change sometime in the future to return undef on an error, setting $!\nas a side effect. This change will not happen in any 2.x version.\n\n*Head*( MESSAGENUMBER [, PREVIEWLINES ] )\nGet the headers of the specified message, either as an array or as a string, depending\non context.\n\nYou can also specify a number of preview lines which will be returned with the headers.\nThis may not be supported by all POP3 server implementations as it is marked as optional\nin the RFC. Submitted by Dennis Moroney <dennis@hub.iwl.net>.\n\n*Body*( MESSAGENUMBER )\nGet the body of the specified message, either as an array of lines or as a string,\ndepending on context.\n\n*BodyToFile*( FILEHANDLE, MESSAGENUMBER )\nGet the body of the specified message and write it to the given file handle. my $fh =\nnew IO::Handle(); $fh->fdopen( fileno( STDOUT ), \"w\" ); $pop->BodyToFile( $fh, 1 );\n\nDoes no stripping of NL or CR.\n\n*HeadAndBody*( MESSAGENUMBER )\nGet the head and body of the specified message, either as an array of lines or as a\nstring, depending on context.\n\nExample\nforeach ( $pop->HeadAndBody( 1 ) ) print $, \"\\n\";\n\nprints out the complete text of message 1.\n\n*HeadAndBodyToFile*( FILEHANDLE, MESSAGENUMBER )\nGet the head and body of the specified message and write it to the given file handle. my\n$fh = new IO::Handle(); $fh->fdopen( fileno( STDOUT ), \"w\" ); $pop->HeadAndBodyToFile(\n$fh, 1 );\n\nDoes no stripping of NL or CR.\n\n*Retrieve*( MESSAGENUMBER )\nSame as HeadAndBody.\n\n*RetrieveToFile*( FILEHANDLE, MESSAGENUMBER )\nSame as HeadAndBodyToFile.\n\n*Delete*( MESSAGENUMBER )\nMark the specified message number as DELETED. Becomes effective upon QUIT (invoking the\nClose method). Can be reset with a Reset message.\n\n*Connect*\nStart the connection to the POP3 server. You can pass in the host and port. Returns 1 if\nthe connection succeeds, or 0 if it fails (Message will contain a reason). The\nconstructor always returns a blessed reference to a Mail::POP3Client obhect. This may\nchange in a version 3.x release, but never in a 2.x release.\n\n*Close* Close the connection gracefully. POP3 says this will perform any pending deletes on the\nserver.\n\n*Alive* Return true or false on whether the connection is active.\n\n*Socket*\nReturn the file descriptor for the socket, or set if supplied.\n\n*Size*  Set/Return the size of the remote mailbox. Set by POPStat.\n\n*Count* Set/Return the number of remote messages. Set during Login.\n\n*Message*\nThe last status message received from the server or a message describing any problem\nencountered.\n\n*State* The internal state of the connection: DEAD, AUTHORIZATION, TRANSACTION.\n\n*POPStat*\nReturn the results of a POP3 STAT command. Sets the size of the mailbox.\n\n*List*([messagenumber])\nReturns the size of the given message number when called with an argument using the\nfollowing format:\n\n<messagenumber> <sizeinbytes>\n\nIf messagenumber is omitted, List behaves the same as ListArray, returning an indexed\narray of the sizes of each message in the same format.\n\nYou can parse the size in bytes using split: ($msgnum, $size) = split('\\s+', $pop ->\nList( n ));\n\n*ListArray*\nReturn a list of sizes of each message. This returns an indexed array, with each message\nnumber as an index (starting from 1) and the value as the next entry on the line. Beware\nthat some servers send additional info for each message for the list command. That info\nmay be lost.\n\n*Uidl*( [MESSAGENUMBER] )\nReturn the unique ID for the given message (or all of them). Returns an indexed array\nwith an entry for each valid message number. Indexing begins at 1 to coincide with the\nserver's indexing.\n\n*Capa*  Query server capabilities, as described in RFC 2449. Returns the capabilities in an\narray. Valid in all states.\n\n*XTND*  Optional extended commands. Transaction state only.\n\n*Last*  Return the number of the last message, retrieved from the server.\n\n*Reset* Tell the server to unmark any message marked for deletion.\n\n*User*( [USERNAME] )\nSet/Return the current user name.\n\n*Pass*( [PASSWORD] )\nSet/Return the current user name.\n\n*Login* Attempt to login to the server connection.\n\n*Host*( [HOSTNAME] )\nSet/Return the current host.\n\n*Port*( [PORTNUMBER] )\nSet/Return the current port number.\n",
            "subsections": []
        },
        "IMAP COMPATIBILITY": {
            "content": "Basic Mail::IMAPClient method calls are also supported: close, connect, login, messagestring,\nPassword, and unseen. Also, empty stubs are provided for Folder, folders, Peek, select, and Uid.\n",
            "subsections": []
        },
        "REQUIREMENTS": {
            "content": "This module does not have mandatory requirements for modules that are not part of the standard\nPerl distribution. However, APOP needs need Digest::MD5 and CRAM-MD5 needs Digest::HMACMD5 and\nMIME::Base64.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Sean Dowd <pop3client@dowds.net>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "CREDITS": {
            "content": "Based loosely on News::NNTPClient by Rodger Anderson <rodger@boi.hp.com>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "perl",
                    "content": "the Digest::MD5 manpage, the Digest::HMACMD5 manpage, the MIME::Base64 manpage\n\nRFC 1939: Post Office Protocol - Version 3\n\nRFC 2195: IMAP/POP AUTHorize Extension for Simple Challenge/Response\n\nRFC 2449: POP3 Extension Mechanism\n"
                }
            ]
        }
    },
    "summary": "Mail::POP3Client - Perl 5 module to talk to a POP3 (RFC1939) server",
    "flags": [],
    "examples": [
        "Here is a simple example to list out the From: and Subject: headers in your remote mailbox:",
        "#!/usr/local/bin/perl",
        "use Mail::POP3Client;",
        "$pop = new Mail::POP3Client( USER     => \"me\",",
        "PASSWORD => \"mypassword\",",
        "HOST     => \"pop3.do.main\" );",
        "for ($i = 1; $i <= $pop->Count(); $i++) {",
        "foreach ( $pop->Head( $i ) ) {",
        "/^(From|Subject):\\s+/i and print $, \"\\n\";",
        "print \"\\n\";"
    ],
    "see_also": []
}