parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="poplib — POP3 protocol client" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/poplib.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/poplib.py This module defines a class, POP3, which encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. The POP3 class supports both the m..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_poplib_e212da4e.png" />15<meta property="og:image:alt" content="Source code: Lib/poplib.py This module defines a class, POP3, which encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. The POP3 class supports both the m..." />16<meta name="description" content="Source code: Lib/poplib.py This module defines a class, POP3, which encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. The POP3 class supports both the m..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>poplib — POP3 protocol client — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="imaplib — IMAP4 protocol client" href="imaplib.html" />43 <link rel="prev" title="ftplib — FTP protocol client" href="ftplib.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/poplib.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h3><a href="../contents.html">Table of Contents</a></h3>106 <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a><ul>108<li><a class="reference internal" href="#pop3-objects">POP3 Objects</a></li>109<li><a class="reference internal" href="#pop3-example">POP3 Example</a></li>110</ul>111</li>112</ul>113 114 </div>115 <div>116 <h4>Previous topic</h4>117 <p class="topless"><a href="ftplib.html"118 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code> — FTP protocol client</a></p>119 </div>120 <div>121 <h4>Next topic</h4>122 <p class="topless"><a href="imaplib.html"123 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code> — IMAP4 protocol client</a></p>124 </div>125 <script>126 document.addEventListener('DOMContentLoaded', () => {127 const title = document.querySelector('meta[property="og:title"]').content;128 const elements = document.querySelectorAll('.improvepage');129 const pageurl = window.location.href.split('?')[0];130 elements.forEach(element => {131 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));132 url.searchParams.set('pagetitle', title);133 url.searchParams.set('pageurl', pageurl);134 url.searchParams.set('pagesource', "library/poplib.rst");135 element.href = url.toString();136 });137 });138 </script>139 <div role="note" aria-label="source link">140 <h3>This page</h3>141 <ul class="this-page-menu">142 <li><a href="../bugs.html">Report a bug</a></li>143 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>144 <li>145 <a href="https://github.com/python/cpython/blob/main/Doc/library/poplib.rst?plain=1"146 rel="nofollow">Show source147 </a>148 </li>149 150 </ul>151 </div>152 </nav>153 </div>154</div>155 156 157 <div class="related" role="navigation" aria-label="Related">158 <h3>Navigation</h3>159 <ul>160 <li class="right" style="margin-right: 10px">161 <a href="../genindex.html" title="General Index"162 accesskey="I">index</a></li>163 <li class="right" >164 <a href="../py-modindex.html" title="Python Module Index"165 >modules</a> |</li>166 <li class="right" >167 <a href="imaplib.html" title="imaplib — IMAP4 protocol client"168 accesskey="N">next</a> |</li>169 <li class="right" >170 <a href="ftplib.html" title="ftplib — FTP protocol client"171 accesskey="P">previous</a> |</li>172 173 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>174 <li><a href="https://www.python.org/">Python</a> »</li>175 <li class="switchers">176 <div class="language_switcher_placeholder"></div>177 <div class="version_switcher_placeholder"></div>178 </li>179 <li>180 181 </li>182 <li id="cpython-language-and-version">183 <a href="../index.html">3.15.0a6 Documentation</a> »184 </li>185 186 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>187 <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">Internet Protocols and Support</a> »</li>188 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a></li>189 <li class="right">190 191 192 <div class="inline-search" role="search">193 <form class="inline-search" action="../search.html" method="get">194 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">195 <input type="submit" value="Go">196 </form>197 </div>198 |199 </li>200 <li class="right">201<label class="theme-selector-label">202 Theme203 <select class="theme-selector" oninput="activateTheme(this.value)">204 <option value="auto" selected>Auto</option>205 <option value="light">Light</option>206 <option value="dark">Dark</option>207 </select>208</label> |</li>209 210 </ul>211 </div> 212 213 <div class="document">214 <div class="documentwrapper">215 <div class="bodywrapper">216 <div class="body" role="main">217 218 <section id="module-poplib">219<span id="poplib-pop3-protocol-client"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client<a class="headerlink" href="#module-poplib" title="Link to this heading">¶</a></h1>220<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/poplib.py">Lib/poplib.py</a></p>221<hr class="docutils" id="index-0" />222<p>This module defines a class, <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a>, which encapsulates a connection to a223POP3 server and implements the protocol as defined in <span class="target" id="index-1"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1939.html"><strong>RFC 1939</strong></a>. The224<code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code> class supports both the minimal and optional command sets from225<span class="target" id="index-2"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1939.html"><strong>RFC 1939</strong></a>. The <code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code> class also supports the <code class="docutils literal notranslate"><span class="pre">STLS</span></code> command introduced226in <span class="target" id="index-3"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2595.html"><strong>RFC 2595</strong></a> to enable encrypted communication on an already established connection.</p>227<p>Additionally, this module provides a class <a class="reference internal" href="#poplib.POP3_SSL" title="poplib.POP3_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3_SSL</span></code></a>, which provides228support for connecting to POP3 servers that use SSL as an underlying protocol229layer.</p>230<p>Note that POP3, though widely supported, is obsolescent. The implementation231quality of POP3 servers varies widely, and too many are quite poor. If your232mailserver supports IMAP, you would be better off using the233<a class="reference internal" href="imaplib.html#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">imaplib.IMAP4</span></code></a> class, as IMAP servers tend to be better implemented.</p>234<div class="availability docutils container">235<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not WASI.</p>236<p>This module does not work or is not available on WebAssembly. See237<a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>238</div>239<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> module provides two classes:</p>240<dl class="py class">241<dt class="sig sig-object py" id="poplib.POP3">242<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">poplib.</span></span><span class="sig-name descname"><span class="pre">POP3</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port=POP3_PORT</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3" title="Link to this definition">¶</a></dt>243<dd><p>This class implements the actual POP3 protocol. The connection is created when244the instance is initialized. If <em>port</em> is omitted, the standard POP3 port (110)245is used. The optional <em>timeout</em> parameter specifies a timeout in seconds for the246connection attempt (if not specified, the global default timeout setting will247be used).</p>248<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.connect</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">host</span></code>, <code class="docutils literal notranslate"><span class="pre">port</span></code>.</p>249<p class="audit-hook"><p>All commands will raise an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a>250<code class="docutils literal notranslate"><span class="pre">poplib.putline</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">line</span></code>,251where <code class="docutils literal notranslate"><span class="pre">line</span></code> is the bytes about to be sent to the remote host.</p>252</p>253<div class="versionchanged">254<p><span class="versionmodified changed">Changed in version 3.9: </span>If the <em>timeout</em> parameter is set to be zero, it will raise a255<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a> to prevent the creation of a non-blocking socket.</p>256</div>257</dd></dl>258 259<dl class="py class">260<dt class="sig sig-object py" id="poplib.POP3_SSL">261<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">poplib.</span></span><span class="sig-name descname"><span class="pre">POP3_SSL</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">POP3_SSL_PORT</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3_SSL" title="Link to this definition">¶</a></dt>262<dd><p>This is a subclass of <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> that connects to the server over an SSL263encrypted socket. If <em>port</em> is not specified, 995, the standard POP3-over-SSL264port is used. <em>timeout</em> works as in the <code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code> constructor.265<em>context</em> is an optional <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> object which allows266bundling SSL configuration options, certificates and private keys into a267single (potentially long-lived) structure. Please read <a class="reference internal" href="ssl.html#ssl-security"><span class="std std-ref">Security considerations</span></a>268for best practices.</p>269<p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">poplib.connect</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code>, <code class="docutils literal notranslate"><span class="pre">host</span></code>, <code class="docutils literal notranslate"><span class="pre">port</span></code>.</p>270<p class="audit-hook"><p>All commands will raise an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a>271<code class="docutils literal notranslate"><span class="pre">poplib.putline</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">line</span></code>,272where <code class="docutils literal notranslate"><span class="pre">line</span></code> is the bytes about to be sent to the remote host.</p>273</p>274<div class="versionchanged">275<p><span class="versionmodified changed">Changed in version 3.2: </span><em>context</em> parameter added.</p>276</div>277<div class="versionchanged">278<p><span class="versionmodified changed">Changed in version 3.4: </span>The class now supports hostname check with279<a class="reference internal" href="ssl.html#ssl.SSLContext.check_hostname" title="ssl.SSLContext.check_hostname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ssl.SSLContext.check_hostname</span></code></a> and <em>Server Name Indication</em> (see280<a class="reference internal" href="ssl.html#ssl.HAS_SNI" title="ssl.HAS_SNI"><code class="xref py py-const docutils literal notranslate"><span class="pre">ssl.HAS_SNI</span></code></a>).</p>281</div>282<div class="versionchanged">283<p><span class="versionmodified changed">Changed in version 3.9: </span>If the <em>timeout</em> parameter is set to be zero, it will raise a284<a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a> to prevent the creation of a non-blocking socket.</p>285</div>286<div class="versionchanged">287<p><span class="versionmodified changed">Changed in version 3.12: </span>The deprecated <em>keyfile</em> and <em>certfile</em> parameters have been removed.</p>288</div>289</dd></dl>290 291<p>One exception is defined as an attribute of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> module:</p>292<dl class="py exception">293<dt class="sig sig-object py" id="poplib.error_proto">294<em class="property"><span class="k"><span class="pre">exception</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">poplib.</span></span><span class="sig-name descname"><span class="pre">error_proto</span></span><a class="headerlink" href="#poplib.error_proto" title="Link to this definition">¶</a></dt>295<dd><p>Exception raised on any errors from this module (errors from <a class="reference internal" href="socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a>296module are not caught). The reason for the exception is passed to the297constructor as a string.</p>298</dd></dl>299 300<div class="admonition seealso">301<p class="admonition-title">See also</p>302<dl class="simple">303<dt>Module <a class="reference internal" href="imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a></dt><dd><p>The standard Python IMAP module.</p>304</dd>305<dt><a class="reference external" href="http://www.catb.org/~esr/fetchmail/fetchmail-FAQ.html">Frequently Asked Questions About Fetchmail</a></dt><dd><p>The FAQ for the <strong class="program">fetchmail</strong> POP/IMAP client collects information on306POP3 server variations and RFC noncompliance that may be useful if you need to307write an application based on the POP protocol.</p>308</dd>309</dl>310</div>311<section id="pop3-objects">312<span id="id1"></span><h2>POP3 Objects<a class="headerlink" href="#pop3-objects" title="Link to this heading">¶</a></h2>313<p>All POP3 commands are represented by methods of the same name, in lowercase;314most return the response text sent by the server.</p>315<p>A <a class="reference internal" href="#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> instance has the following methods:</p>316<dl class="py method">317<dt class="sig sig-object py" id="poplib.POP3.set_debuglevel">318<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">set_debuglevel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">level</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.set_debuglevel" title="Link to this definition">¶</a></dt>319<dd><p>Set the instance’s debugging level. This controls the amount of debugging320output printed. The default, <code class="docutils literal notranslate"><span class="pre">0</span></code>, produces no debugging output. A value of321<code class="docutils literal notranslate"><span class="pre">1</span></code> produces a moderate amount of debugging output, generally a single line322per request. A value of <code class="docutils literal notranslate"><span class="pre">2</span></code> or higher produces the maximum amount of323debugging output, logging each line sent and received on the control connection.</p>324</dd></dl>325 326<dl class="py method">327<dt class="sig sig-object py" id="poplib.POP3.getwelcome">328<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">getwelcome</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.getwelcome" title="Link to this definition">¶</a></dt>329<dd><p>Returns the greeting string sent by the POP3 server.</p>330</dd></dl>331 332<dl class="py method">333<dt class="sig sig-object py" id="poplib.POP3.capa">334<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">capa</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.capa" title="Link to this definition">¶</a></dt>335<dd><p>Query the server’s capabilities as specified in <span class="target" id="index-4"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2449.html"><strong>RFC 2449</strong></a>.336Returns a dictionary in the form <code class="docutils literal notranslate"><span class="pre">{'name':</span> <span class="pre">['param'...]}</span></code>.</p>337<div class="versionadded">338<p><span class="versionmodified added">Added in version 3.4.</span></p>339</div>340</dd></dl>341 342<dl class="py method">343<dt class="sig sig-object py" id="poplib.POP3.user">344<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">user</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">username</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.user" title="Link to this definition">¶</a></dt>345<dd><p>Send user command, response should indicate that a password is required.</p>346</dd></dl>347 348<dl class="py method">349<dt class="sig sig-object py" id="poplib.POP3.pass_">350<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">pass_</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">password</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.pass_" title="Link to this definition">¶</a></dt>351<dd><p>Send password, response includes message count and mailbox size. Note: the352mailbox on the server is locked until <a class="reference internal" href="#poplib.POP3.quit" title="poplib.POP3.quit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">quit()</span></code></a> is called.</p>353</dd></dl>354 355<dl class="py method">356<dt class="sig sig-object py" id="poplib.POP3.apop">357<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">apop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">user</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">secret</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.apop" title="Link to this definition">¶</a></dt>358<dd><p>Use the more secure APOP authentication to log into the POP3 server.</p>359</dd></dl>360 361<dl class="py method">362<dt class="sig sig-object py" id="poplib.POP3.rpop">363<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">rpop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">user</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.rpop" title="Link to this definition">¶</a></dt>364<dd><p>Use RPOP authentication (similar to UNIX r-commands) to log into POP3 server.</p>365</dd></dl>366 367<dl class="py method">368<dt class="sig sig-object py" id="poplib.POP3.stat">369<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">stat</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.stat" title="Link to this definition">¶</a></dt>370<dd><p>Get mailbox status. The result is a tuple of 2 integers: <code class="docutils literal notranslate"><span class="pre">(message</span> <span class="pre">count,</span>371<span class="pre">mailbox</span> <span class="pre">size)</span></code>.</p>372</dd></dl>373 374<dl class="py method">375<dt class="sig sig-object py" id="poplib.POP3.list">376<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">list</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.list" title="Link to this definition">¶</a></dt>377<dd><p>Request message list, result is in the form <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['mesg_num</span> <span class="pre">octets',</span>378<span class="pre">...],</span> <span class="pre">octets)</span></code>. If <em>which</em> is set, it is the message to list.</p>379</dd></dl>380 381<dl class="py method">382<dt class="sig sig-object py" id="poplib.POP3.retr">383<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">retr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.retr" title="Link to this definition">¶</a></dt>384<dd><p>Retrieve whole message number <em>which</em>, and set its seen flag. Result is in form385<code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['line',</span> <span class="pre">...],</span> <span class="pre">octets)</span></code>.</p>386</dd></dl>387 388<dl class="py method">389<dt class="sig sig-object py" id="poplib.POP3.dele">390<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">dele</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.dele" title="Link to this definition">¶</a></dt>391<dd><p>Flag message number <em>which</em> for deletion. On most servers deletions are not392actually performed until QUIT (the major exception is Eudora QPOP, which393deliberately violates the RFCs by doing pending deletes on any disconnect).</p>394</dd></dl>395 396<dl class="py method">397<dt class="sig sig-object py" id="poplib.POP3.rset">398<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">rset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.rset" title="Link to this definition">¶</a></dt>399<dd><p>Remove any deletion marks for the mailbox.</p>400</dd></dl>401 402<dl class="py method">403<dt class="sig sig-object py" id="poplib.POP3.noop">404<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">noop</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.noop" title="Link to this definition">¶</a></dt>405<dd><p>Do nothing. Might be used as a keep-alive.</p>406</dd></dl>407 408<dl class="py method">409<dt class="sig sig-object py" id="poplib.POP3.quit">410<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">quit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.quit" title="Link to this definition">¶</a></dt>411<dd><p>Signoff: commit changes, unlock mailbox, drop connection.</p>412</dd></dl>413 414<dl class="py method">415<dt class="sig sig-object py" id="poplib.POP3.top">416<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">top</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">howmuch</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.top" title="Link to this definition">¶</a></dt>417<dd><p>Retrieves the message header plus <em>howmuch</em> lines of the message after the418header of message number <em>which</em>. Result is in form <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['line',</span> <span class="pre">...],</span>419<span class="pre">octets)</span></code>.</p>420<p>The POP3 TOP command this method uses, unlike the RETR command, doesn’t set the421message’s seen flag; unfortunately, TOP is poorly specified in the RFCs and is422frequently broken in off-brand servers. Test this method by hand against the423POP3 servers you will use before trusting it.</p>424</dd></dl>425 426<dl class="py method">427<dt class="sig sig-object py" id="poplib.POP3.uidl">428<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">uidl</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">which</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.uidl" title="Link to this definition">¶</a></dt>429<dd><p>Return message digest (unique id) list. If <em>which</em> is specified, result contains430the unique id for that message in the form <code class="docutils literal notranslate"><span class="pre">'response</span> <span class="pre">mesgnum</span> <span class="pre">uid</span></code>, otherwise431result is list <code class="docutils literal notranslate"><span class="pre">(response,</span> <span class="pre">['mesgnum</span> <span class="pre">uid',</span> <span class="pre">...],</span> <span class="pre">octets)</span></code>.</p>432</dd></dl>433 434<dl class="py method">435<dt class="sig sig-object py" id="poplib.POP3.utf8">436<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">utf8</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.utf8" title="Link to this definition">¶</a></dt>437<dd><p>Try to switch to UTF-8 mode. Returns the server response if successful,438raises <a class="reference internal" href="#poplib.error_proto" title="poplib.error_proto"><code class="xref py py-class docutils literal notranslate"><span class="pre">error_proto</span></code></a> if not. Specified in <span class="target" id="index-5"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6856.html"><strong>RFC 6856</strong></a>.</p>439<div class="versionadded">440<p><span class="versionmodified added">Added in version 3.5.</span></p>441</div>442</dd></dl>443 444<dl class="py method">445<dt class="sig sig-object py" id="poplib.POP3.stls">446<span class="sig-prename descclassname"><span class="pre">POP3.</span></span><span class="sig-name descname"><span class="pre">stls</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#poplib.POP3.stls" title="Link to this definition">¶</a></dt>447<dd><p>Start a TLS session on the active connection as specified in <span class="target" id="index-6"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2595.html"><strong>RFC 2595</strong></a>.448This is only allowed before user authentication</p>449<p><em>context</em> parameter is a <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> object which allows450bundling SSL configuration options, certificates and private keys into451a single (potentially long-lived) structure. Please read <a class="reference internal" href="ssl.html#ssl-security"><span class="std std-ref">Security considerations</span></a>452for best practices.</p>453<p>This method supports hostname checking via454<a class="reference internal" href="ssl.html#ssl.SSLContext.check_hostname" title="ssl.SSLContext.check_hostname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ssl.SSLContext.check_hostname</span></code></a> and <em>Server Name Indication</em> (see455<a class="reference internal" href="ssl.html#ssl.HAS_SNI" title="ssl.HAS_SNI"><code class="xref py py-const docutils literal notranslate"><span class="pre">ssl.HAS_SNI</span></code></a>).</p>456<div class="versionadded">457<p><span class="versionmodified added">Added in version 3.4.</span></p>458</div>459</dd></dl>460 461<p>Instances of <a class="reference internal" href="#poplib.POP3_SSL" title="poplib.POP3_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3_SSL</span></code></a> have no additional methods. The interface of this462subclass is identical to its parent.</p>463</section>464<section id="pop3-example">465<span id="id2"></span><h2>POP3 Example<a class="headerlink" href="#pop3-example" title="Link to this heading">¶</a></h2>466<p>Here is a minimal example (without error checking) that opens a mailbox and467retrieves and prints all messages:</p>468<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">getpass</span><span class="o">,</span><span class="w"> </span><span class="nn">poplib</span>469 470<span class="n">M</span> <span class="o">=</span> <span class="n">poplib</span><span class="o">.</span><span class="n">POP3</span><span class="p">(</span><span class="s1">'localhost'</span><span class="p">)</span>471<span class="n">M</span><span class="o">.</span><span class="n">user</span><span class="p">(</span><span class="n">getpass</span><span class="o">.</span><span class="n">getuser</span><span class="p">())</span>472<span class="n">M</span><span class="o">.</span><span class="n">pass_</span><span class="p">(</span><span class="n">getpass</span><span class="o">.</span><span class="n">getpass</span><span class="p">())</span>473<span class="n">numMessages</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">M</span><span class="o">.</span><span class="n">list</span><span class="p">()[</span><span class="mi">1</span><span class="p">])</span>474<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">numMessages</span><span class="p">):</span>475 <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">M</span><span class="o">.</span><span class="n">retr</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)[</span><span class="mi">1</span><span class="p">]:</span>476 <span class="nb">print</span><span class="p">(</span><span class="n">j</span><span class="p">)</span>477</pre></div>478</div>479<p>At the end of the module, there is a test section that contains a more extensive480example of usage.</p>481</section>482</section>483 484 485 <div class="clearer"></div>486 </div>487 </div>488 </div>489 <div class="sphinxsidebar" role="navigation" aria-label="Main">490 <div class="sphinxsidebarwrapper">491 <div>492 <h3><a href="../contents.html">Table of Contents</a></h3>493 <ul>494<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a><ul>495<li><a class="reference internal" href="#pop3-objects">POP3 Objects</a></li>496<li><a class="reference internal" href="#pop3-example">POP3 Example</a></li>497</ul>498</li>499</ul>500 501 </div>502 <div>503 <h4>Previous topic</h4>504 <p class="topless"><a href="ftplib.html"505 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code> — FTP protocol client</a></p>506 </div>507 <div>508 <h4>Next topic</h4>509 <p class="topless"><a href="imaplib.html"510 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code> — IMAP4 protocol client</a></p>511 </div>512 <script>513 document.addEventListener('DOMContentLoaded', () => {514 const title = document.querySelector('meta[property="og:title"]').content;515 const elements = document.querySelectorAll('.improvepage');516 const pageurl = window.location.href.split('?')[0];517 elements.forEach(element => {518 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));519 url.searchParams.set('pagetitle', title);520 url.searchParams.set('pageurl', pageurl);521 url.searchParams.set('pagesource', "library/poplib.rst");522 element.href = url.toString();523 });524 });525 </script>526 <div role="note" aria-label="source link">527 <h3>This page</h3>528 <ul class="this-page-menu">529 <li><a href="../bugs.html">Report a bug</a></li>530 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>531 <li>532 <a href="https://github.com/python/cpython/blob/main/Doc/library/poplib.rst?plain=1"533 rel="nofollow">Show source534 </a>535 </li>536 537 </ul>538 </div>539 </div>540<div id="sidebarbutton" title="Collapse sidebar">541<span>«</span>542</div>543 544 </div>545 <div class="clearer"></div>546 </div> 547 <div class="related" role="navigation" aria-label="Related">548 <h3>Navigation</h3>549 <ul>550 <li class="right" style="margin-right: 10px">551 <a href="../genindex.html" title="General Index"552 >index</a></li>553 <li class="right" >554 <a href="../py-modindex.html" title="Python Module Index"555 >modules</a> |</li>556 <li class="right" >557 <a href="imaplib.html" title="imaplib — IMAP4 protocol client"558 >next</a> |</li>559 <li class="right" >560 <a href="ftplib.html" title="ftplib — FTP protocol client"561 >previous</a> |</li>562 563 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>564 <li><a href="https://www.python.org/">Python</a> »</li>565 <li class="switchers">566 <div class="language_switcher_placeholder"></div>567 <div class="version_switcher_placeholder"></div>568 </li>569 <li>570 571 </li>572 <li id="cpython-language-and-version">573 <a href="../index.html">3.15.0a6 Documentation</a> »574 </li>575 576 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>577 <li class="nav-item nav-item-2"><a href="internet.html" >Internet Protocols and Support</a> »</li>578 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a></li>579 <li class="right">580 581 582 <div class="inline-search" role="search">583 <form class="inline-search" action="../search.html" method="get">584 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">585 <input type="submit" value="Go">586 </form>587 </div>588 |589 </li>590 <li class="right">591<label class="theme-selector-label">592 Theme593 <select class="theme-selector" oninput="activateTheme(this.value)">594 <option value="auto" selected>Auto</option>595 <option value="light">Light</option>596 <option value="dark">Dark</option>597 </select>598</label> |</li>599 600 </ul>601 </div> 602 <div class="footer">603 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.604 <br>605 This page is licensed under the Python Software Foundation License Version 2.606 <br>607 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.608 <br>609 610 See <a href="/license.html">History and License</a> for more information.<br>611 612 613 <br>614 615 The Python Software Foundation is a non-profit corporation.616<a href="https://www.python.org/psf/donations/">Please donate.</a>617<br>618 <br>619 Last updated on Mar 10, 2026 (08:58 UTC).620 621 <a href="/bugs.html">Found a bug</a>?622 623 <br>624 625 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.626 </div>627 628 </body>629</html>