HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/doc/python3.10-doc/html/library/smtpd.html
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>smtpd — SMTP Server &#8212; Python 3.10.12 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?2022.1" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    
    <script src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.10.12 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="sndhdr — Determine type of sound file" href="sndhdr.html" />
    <link rel="prev" title="pipes — Interface to shell pipelines" href="pipes.html" />
    <link rel="canonical" href="file:///usr/share/doc/python3.10/html/library/smtpd.html" />
    
      
    

    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
            <script type="text/javascript" src="../_static/copybutton.js"></script>
            <script type="text/javascript" src="../_static/menu.js"></script> 

  </head>
<body>
<div class="mobile-nav">
    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
    <label for="menuToggler" class="toggler__label">
        <span></span>
    </label>
    <nav class="nav-content" role="navigation">
         <a href="https://www.python.org/" class="nav-logo">
             <img src="../_static/py.svg" alt="Logo"/>
         </a>
        <div class="version_switcher_placeholder"></div>
        <form role="search" class="search" action="../search.html" method="get">
            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
                <path fill-rule="nonzero"
                        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" fill="#444"></path>
            </svg>
            <input type="text" name="q" aria-label="Quick search"/>
            <input type="submit" value="Go"/>
        </form>
    </nav>
    <div class="menu-wrapper">
        <nav class="menu" role="navigation" aria-label="main navigation">
            <div class="language_switcher_placeholder"></div>
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> — SMTP Server</a><ul>
<li><a class="reference internal" href="#smtpserver-objects">SMTPServer Objects</a></li>
<li><a class="reference internal" href="#debuggingserver-objects">DebuggingServer Objects</a></li>
<li><a class="reference internal" href="#pureproxy-objects">PureProxy Objects</a></li>
<li><a class="reference internal" href="#mailmanproxy-objects">MailmanProxy Objects</a></li>
<li><a class="reference internal" href="#smtpchannel-objects">SMTPChannel Objects</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="pipes.html"
                        title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code> — Interface to shell pipelines</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="sndhdr.html"
                        title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sndhdr</span></code> — Determine type of sound file</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.10/Doc/library/smtpd.rst"
            rel="nofollow">Show Source
        </a>
      </li>
    </ul>
  </div>
        </nav>
    </div>
</div>

  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="sndhdr.html" title="sndhdr — Determine type of sound file"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pipes.html" title="pipes — Interface to shell pipelines"
             accesskey="P">previous</a> |</li>

          <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
          <li><a href="https://www.python.org/">Python</a> &#187;</li>
          <li class="switchers">
            <div class="language_switcher_placeholder"></div>
            <div class="version_switcher_placeholder"></div>
          </li>
          <li>
              
          </li>
    <li id="cpython-language-and-version">
      <a href="../index.html">3.10.12 Documentation</a> &#187;
    </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="superseded.html" accesskey="U">Superseded Modules</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> — SMTP Server</a></li>
                <li class="right">
                    

    <div class="inline-search" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
                     |
                </li>
            
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-smtpd">
<span id="smtpd-smtp-server"></span><h1><a class="reference internal" href="#module-smtpd" title="smtpd: A SMTP server implementation in Python. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code></a> — SMTP Server<a class="headerlink" href="#module-smtpd" title="Permalink to this headline">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.10/Lib/smtpd.py">Lib/smtpd.py</a></p>
<hr class="docutils" />
<p>This module offers several classes to implement SMTP (email) servers.</p>
<div class="deprecated">
<p><span class="versionmodified deprecated">Deprecated since version 3.6: </span><a class="reference internal" href="#module-smtpd" title="smtpd: A SMTP server implementation in Python. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code></a> will be removed in Python 3.12
(see <span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0594#smtpd"><strong>PEP 594</strong></a> for details).
The <a class="reference external" href="https://aiosmtpd.readthedocs.io/">aiosmtpd</a> package is a recommended
replacement for this module.  It is based on <a class="reference internal" href="asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> and provides a
more straightforward API.</p>
</div>
<p>Several server implementations are present; one is a generic
do-nothing implementation, which can be overridden, while the other two offer
specific mail-sending strategies.</p>
<p>Additionally the SMTPChannel may be extended to implement very specific
interaction behaviour with SMTP clients.</p>
<p>The code supports <span class="target" id="index-1"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5321.html"><strong>RFC 5321</strong></a>, plus the <span class="target" id="index-2"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1870.html"><strong>RFC 1870</strong></a> SIZE and <span class="target" id="index-3"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6531.html"><strong>RFC 6531</strong></a>
SMTPUTF8 extensions.</p>
<section id="smtpserver-objects">
<h2>SMTPServer Objects<a class="headerlink" href="#smtpserver-objects" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="smtpd.SMTPServer">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">smtpd.</span></span><span class="sig-name descname"><span class="pre">SMTPServer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">localaddr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">remoteaddr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data_size_limit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">33554432</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">map</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">enable_SMTPUTF8</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode_data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#smtpd.SMTPServer" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new <a class="reference internal" href="#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a> object, which binds to local address
<em>localaddr</em>.  It will treat <em>remoteaddr</em> as an upstream SMTP relayer.  Both
<em>localaddr</em> and <em>remoteaddr</em> should be a <a class="reference internal" href="socket.html#host-port"><span class="std std-ref">(host, port)</span></a>
tuple.  The object inherits from <a class="reference internal" href="asyncore.html#asyncore.dispatcher" title="asyncore.dispatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncore.dispatcher</span></code></a>, and so will
insert itself into <a class="reference internal" href="asyncore.html#module-asyncore" title="asyncore: A base class for developing asynchronous socket handling services. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code></a>’s event loop on instantiation.</p>
<p><em>data_size_limit</em> specifies the maximum number of bytes that will be
accepted in a <code class="docutils literal notranslate"><span class="pre">DATA</span></code> command.  A value of <code class="docutils literal notranslate"><span class="pre">None</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> means no
limit.</p>
<p><em>map</em> is the socket map to use for connections (an initially empty
dictionary is a suitable value).  If not specified the <a class="reference internal" href="asyncore.html#module-asyncore" title="asyncore: A base class for developing asynchronous socket handling services. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code></a>
global socket map is used.</p>
<p><em>enable_SMTPUTF8</em> determines whether the <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> extension (as defined
in <span class="target" id="index-4"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6531.html"><strong>RFC 6531</strong></a>) should be enabled.  The default is <code class="docutils literal notranslate"><span class="pre">False</span></code>.
When <code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> is accepted as a parameter to the <code class="docutils literal notranslate"><span class="pre">MAIL</span></code>
command and when present is passed to <a class="reference internal" href="#smtpd.SMTPServer.process_message" title="smtpd.SMTPServer.process_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">process_message()</span></code></a> in the
<code class="docutils literal notranslate"><span class="pre">kwargs['mail_options']</span></code> list.  <em>decode_data</em> and <em>enable_SMTPUTF8</em>
cannot be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> at the same time.</p>
<p><em>decode_data</em> specifies whether the data portion of the SMTP transaction
should be decoded using UTF-8.  When <em>decode_data</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> (the
default), the server advertises the <code class="docutils literal notranslate"><span class="pre">8BITMIME</span></code>
extension (<span class="target" id="index-5"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6152.html"><strong>RFC 6152</strong></a>), accepts the <code class="docutils literal notranslate"><span class="pre">BODY=8BITMIME</span></code> parameter to
the <code class="docutils literal notranslate"><span class="pre">MAIL</span></code> command, and when present passes it to <a class="reference internal" href="#smtpd.SMTPServer.process_message" title="smtpd.SMTPServer.process_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">process_message()</span></code></a>
in the <code class="docutils literal notranslate"><span class="pre">kwargs['mail_options']</span></code> list. <em>decode_data</em> and <em>enable_SMTPUTF8</em>
cannot be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> at the same time.</p>
<dl class="py method">
<dt class="sig sig-object py" id="smtpd.SMTPServer.process_message">
<span class="sig-name descname"><span class="pre">process_message</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">peer</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mailfrom</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rcpttos</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#smtpd.SMTPServer.process_message" title="Permalink to this definition">¶</a></dt>
<dd><p>Raise a <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> exception. Override this in subclasses to
do something useful with this message. Whatever was passed in the
constructor as <em>remoteaddr</em> will be available as the <code class="xref py py-attr docutils literal notranslate"><span class="pre">_remoteaddr</span></code>
attribute. <em>peer</em> is the remote host’s address, <em>mailfrom</em> is the envelope
originator, <em>rcpttos</em> are the envelope recipients and <em>data</em> is a string
containing the contents of the e-mail (which should be in <span class="target" id="index-6"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5321.html"><strong>RFC 5321</strong></a>
format).</p>
<p>If the <em>decode_data</em> constructor keyword is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, the <em>data</em>
argument will be a unicode string.  If it is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, it
will be a bytes object.</p>
<p><em>kwargs</em> is a dictionary containing additional information. It is empty
if <code class="docutils literal notranslate"><span class="pre">decode_data=True</span></code> was given as an init argument, otherwise
it contains the following keys:</p>
<blockquote>
<div><dl class="simple">
<dt><em>mail_options</em>:</dt><dd><p>a list of all received parameters to the <code class="docutils literal notranslate"><span class="pre">MAIL</span></code>
command (the elements are uppercase strings; example:
<code class="docutils literal notranslate"><span class="pre">['BODY=8BITMIME',</span> <span class="pre">'SMTPUTF8']</span></code>).</p>
</dd>
<dt><em>rcpt_options</em>:</dt><dd><p>same as <em>mail_options</em> but for the <code class="docutils literal notranslate"><span class="pre">RCPT</span></code> command.
Currently no <code class="docutils literal notranslate"><span class="pre">RCPT</span> <span class="pre">TO</span></code> options are supported, so for now
this will always be an empty list.</p>
</dd>
</dl>
</div></blockquote>
<p>Implementations of <code class="docutils literal notranslate"><span class="pre">process_message</span></code> should use the <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code>
signature to accept arbitrary keyword arguments, since future feature
enhancements may add keys to the kwargs dictionary.</p>
<p>Return <code class="docutils literal notranslate"><span class="pre">None</span></code> to request a normal <code class="docutils literal notranslate"><span class="pre">250</span> <span class="pre">Ok</span></code> response; otherwise
return the desired response string in <span class="target" id="index-7"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5321.html"><strong>RFC 5321</strong></a> format.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPServer.channel_class">
<span class="sig-name descname"><span class="pre">channel_class</span></span><a class="headerlink" href="#smtpd.SMTPServer.channel_class" title="Permalink to this definition">¶</a></dt>
<dd><p>Override this in subclasses to use a custom <a class="reference internal" href="#smtpd.SMTPChannel" title="smtpd.SMTPChannel"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code></a> for
managing SMTP clients.</p>
</dd></dl>

<div class="versionadded">
<p><span class="versionmodified added">New in version 3.4: </span>The <em>map</em> constructor argument.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 3.5: </span><em>localaddr</em> and <em>remoteaddr</em> may now contain IPv6 addresses.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.5: </span>The <em>decode_data</em> and <em>enable_SMTPUTF8</em> constructor parameters, and the
<em>kwargs</em> parameter to <a class="reference internal" href="#smtpd.SMTPServer.process_message" title="smtpd.SMTPServer.process_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">process_message()</span></code></a> when <em>decode_data</em> is
<code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 3.6: </span><em>decode_data</em> is now <code class="docutils literal notranslate"><span class="pre">False</span></code> by default.</p>
</div>
</dd></dl>

</section>
<section id="debuggingserver-objects">
<h2>DebuggingServer Objects<a class="headerlink" href="#debuggingserver-objects" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="smtpd.DebuggingServer">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">smtpd.</span></span><span class="sig-name descname"><span class="pre">DebuggingServer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">localaddr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">remoteaddr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#smtpd.DebuggingServer" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new debugging server.  Arguments are as per <a class="reference internal" href="#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a>.
Messages will be discarded, and printed on stdout.</p>
</dd></dl>

</section>
<section id="pureproxy-objects">
<h2>PureProxy Objects<a class="headerlink" href="#pureproxy-objects" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="smtpd.PureProxy">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">smtpd.</span></span><span class="sig-name descname"><span class="pre">PureProxy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">localaddr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">remoteaddr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#smtpd.PureProxy" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new pure proxy server. Arguments are as per <a class="reference internal" href="#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a>.
Everything will be relayed to <em>remoteaddr</em>.  Note that running this has a good
chance to make you into an open relay, so please be careful.</p>
</dd></dl>

</section>
<section id="mailmanproxy-objects">
<h2>MailmanProxy Objects<a class="headerlink" href="#mailmanproxy-objects" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="smtpd.MailmanProxy">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">smtpd.</span></span><span class="sig-name descname"><span class="pre">MailmanProxy</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">localaddr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">remoteaddr</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#smtpd.MailmanProxy" title="Permalink to this definition">¶</a></dt>
<dd><div class="deprecated-removed">
<p><span class="versionmodified">Deprecated since version 3.9, will be removed in version 3.11: </span><a class="reference internal" href="#smtpd.MailmanProxy" title="smtpd.MailmanProxy"><code class="xref py py-class docutils literal notranslate"><span class="pre">MailmanProxy</span></code></a> is deprecated, it depends on a <code class="docutils literal notranslate"><span class="pre">Mailman</span></code>
module which no longer exists and therefore is already broken.</p>
</div>
<p>Create a new pure proxy server. Arguments are as per <a class="reference internal" href="#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a>.
Everything will be relayed to <em>remoteaddr</em>, unless local mailman configurations
knows about an address, in which case it will be handled via mailman.  Note that
running this has a good chance to make you into an open relay, so please be
careful.</p>
</dd></dl>

</section>
<section id="smtpchannel-objects">
<h2>SMTPChannel Objects<a class="headerlink" href="#smtpchannel-objects" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="smtpd.SMTPChannel">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">smtpd.</span></span><span class="sig-name descname"><span class="pre">SMTPChannel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">server</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">conn</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">addr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">data_size_limit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">33554432</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">map</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">enable_SMTPUTF8</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode_data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#smtpd.SMTPChannel" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new <a class="reference internal" href="#smtpd.SMTPChannel" title="smtpd.SMTPChannel"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code></a> object which manages the communication
between the server and a single SMTP client.</p>
<p><em>conn</em> and <em>addr</em> are as per the instance variables described below.</p>
<p><em>data_size_limit</em> specifies the maximum number of bytes that will be
accepted in a <code class="docutils literal notranslate"><span class="pre">DATA</span></code> command.  A value of <code class="docutils literal notranslate"><span class="pre">None</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> means no
limit.</p>
<p><em>enable_SMTPUTF8</em> determines whether the <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> extension (as defined
in <span class="target" id="index-8"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6531.html"><strong>RFC 6531</strong></a>) should be enabled.  The default is <code class="docutils literal notranslate"><span class="pre">False</span></code>.
<em>decode_data</em> and <em>enable_SMTPUTF8</em> cannot be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> at the same
time.</p>
<p>A dictionary can be specified in <em>map</em> to avoid using a global socket map.</p>
<p><em>decode_data</em> specifies whether the data portion of the SMTP transaction
should be decoded using UTF-8.  The default is <code class="docutils literal notranslate"><span class="pre">False</span></code>.
<em>decode_data</em> and <em>enable_SMTPUTF8</em> cannot be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> at the same
time.</p>
<p>To use a custom SMTPChannel implementation you need to override the
<a class="reference internal" href="#smtpd.SMTPServer.channel_class" title="smtpd.SMTPServer.channel_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SMTPServer.channel_class</span></code></a> of your <a class="reference internal" href="#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a>.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 3.5: </span>The <em>decode_data</em> and <em>enable_SMTPUTF8</em> parameters were added.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 3.6: </span><em>decode_data</em> is now <code class="docutils literal notranslate"><span class="pre">False</span></code> by default.</p>
</div>
<p>The <a class="reference internal" href="#smtpd.SMTPChannel" title="smtpd.SMTPChannel"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code></a> has the following instance variables:</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.smtp_server">
<span class="sig-name descname"><span class="pre">smtp_server</span></span><a class="headerlink" href="#smtpd.SMTPChannel.smtp_server" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds the <a class="reference internal" href="#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a> that spawned this channel.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.conn">
<span class="sig-name descname"><span class="pre">conn</span></span><a class="headerlink" href="#smtpd.SMTPChannel.conn" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds the socket object connecting to the client.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.addr">
<span class="sig-name descname"><span class="pre">addr</span></span><a class="headerlink" href="#smtpd.SMTPChannel.addr" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds the address of the client, the second value returned by
<a class="reference internal" href="socket.html#socket.socket.accept" title="socket.socket.accept"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.accept</span></code></a></p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.received_lines">
<span class="sig-name descname"><span class="pre">received_lines</span></span><a class="headerlink" href="#smtpd.SMTPChannel.received_lines" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds a list of the line strings (decoded using UTF-8) received from
the client. The lines have their <code class="docutils literal notranslate"><span class="pre">&quot;\r\n&quot;</span></code> line ending translated to
<code class="docutils literal notranslate"><span class="pre">&quot;\n&quot;</span></code>.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.smtp_state">
<span class="sig-name descname"><span class="pre">smtp_state</span></span><a class="headerlink" href="#smtpd.SMTPChannel.smtp_state" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds the current state of the channel. This will be either
<code class="xref py py-attr docutils literal notranslate"><span class="pre">COMMAND</span></code> initially and then <code class="xref py py-attr docutils literal notranslate"><span class="pre">DATA</span></code> after the client sends
a “DATA” line.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.seen_greeting">
<span class="sig-name descname"><span class="pre">seen_greeting</span></span><a class="headerlink" href="#smtpd.SMTPChannel.seen_greeting" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds a string containing the greeting sent by the client in its “HELO”.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.mailfrom">
<span class="sig-name descname"><span class="pre">mailfrom</span></span><a class="headerlink" href="#smtpd.SMTPChannel.mailfrom" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds a string containing the address identified in the “MAIL FROM:” line
from the client.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.rcpttos">
<span class="sig-name descname"><span class="pre">rcpttos</span></span><a class="headerlink" href="#smtpd.SMTPChannel.rcpttos" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds a list of strings containing the addresses identified in the
“RCPT TO:” lines from the client.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.received_data">
<span class="sig-name descname"><span class="pre">received_data</span></span><a class="headerlink" href="#smtpd.SMTPChannel.received_data" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds a string containing all of the data sent by the client during the
DATA state, up to but not including the terminating <code class="docutils literal notranslate"><span class="pre">&quot;\r\n.\r\n&quot;</span></code>.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.fqdn">
<span class="sig-name descname"><span class="pre">fqdn</span></span><a class="headerlink" href="#smtpd.SMTPChannel.fqdn" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds the fully qualified domain name of the server as returned by
<a class="reference internal" href="socket.html#socket.getfqdn" title="socket.getfqdn"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.getfqdn()</span></code></a>.</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="smtpd.SMTPChannel.peer">
<span class="sig-name descname"><span class="pre">peer</span></span><a class="headerlink" href="#smtpd.SMTPChannel.peer" title="Permalink to this definition">¶</a></dt>
<dd><p>Holds the name of the client peer as returned by <code class="docutils literal notranslate"><span class="pre">conn.getpeername()</span></code>
where <code class="docutils literal notranslate"><span class="pre">conn</span></code> is <a class="reference internal" href="#smtpd.SMTPChannel.conn" title="smtpd.SMTPChannel.conn"><code class="xref py py-attr docutils literal notranslate"><span class="pre">conn</span></code></a>.</p>
</dd></dl>

<p>The <a class="reference internal" href="#smtpd.SMTPChannel" title="smtpd.SMTPChannel"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code></a> operates by invoking methods named <code class="docutils literal notranslate"><span class="pre">smtp_&lt;command&gt;</span></code>
upon reception of a command line from the client. Built into the base
<a class="reference internal" href="#smtpd.SMTPChannel" title="smtpd.SMTPChannel"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code></a> class are methods for handling the following commands
(and responding to them appropriately):</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 11%" />
<col style="width: 89%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Command</p></th>
<th class="head"><p>Action taken</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>HELO</p></td>
<td><p>Accepts the greeting from the client and stores it in
<a class="reference internal" href="#smtpd.SMTPChannel.seen_greeting" title="smtpd.SMTPChannel.seen_greeting"><code class="xref py py-attr docutils literal notranslate"><span class="pre">seen_greeting</span></code></a>.  Sets server to base command mode.</p></td>
</tr>
<tr class="row-odd"><td><p>EHLO</p></td>
<td><p>Accepts the greeting from the client and stores it in
<a class="reference internal" href="#smtpd.SMTPChannel.seen_greeting" title="smtpd.SMTPChannel.seen_greeting"><code class="xref py py-attr docutils literal notranslate"><span class="pre">seen_greeting</span></code></a>.  Sets server to extended command mode.</p></td>
</tr>
<tr class="row-even"><td><p>NOOP</p></td>
<td><p>Takes no action.</p></td>
</tr>
<tr class="row-odd"><td><p>QUIT</p></td>
<td><p>Closes the connection cleanly.</p></td>
</tr>
<tr class="row-even"><td><p>MAIL</p></td>
<td><p>Accepts the “MAIL FROM:” syntax and stores the supplied address as
<a class="reference internal" href="#smtpd.SMTPChannel.mailfrom" title="smtpd.SMTPChannel.mailfrom"><code class="xref py py-attr docutils literal notranslate"><span class="pre">mailfrom</span></code></a>.  In extended command mode, accepts the
<span class="target" id="index-9"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1870.html"><strong>RFC 1870</strong></a> SIZE attribute and responds appropriately based on the
value of <em>data_size_limit</em>.</p></td>
</tr>
<tr class="row-odd"><td><p>RCPT</p></td>
<td><p>Accepts the “RCPT TO:” syntax and stores the supplied addresses in
the <a class="reference internal" href="#smtpd.SMTPChannel.rcpttos" title="smtpd.SMTPChannel.rcpttos"><code class="xref py py-attr docutils literal notranslate"><span class="pre">rcpttos</span></code></a> list.</p></td>
</tr>
<tr class="row-even"><td><p>RSET</p></td>
<td><p>Resets the <a class="reference internal" href="#smtpd.SMTPChannel.mailfrom" title="smtpd.SMTPChannel.mailfrom"><code class="xref py py-attr docutils literal notranslate"><span class="pre">mailfrom</span></code></a>, <a class="reference internal" href="#smtpd.SMTPChannel.rcpttos" title="smtpd.SMTPChannel.rcpttos"><code class="xref py py-attr docutils literal notranslate"><span class="pre">rcpttos</span></code></a>, and
<a class="reference internal" href="#smtpd.SMTPChannel.received_data" title="smtpd.SMTPChannel.received_data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">received_data</span></code></a>, but not the greeting.</p></td>
</tr>
<tr class="row-odd"><td><p>DATA</p></td>
<td><p>Sets the internal state to <code class="xref py py-attr docutils literal notranslate"><span class="pre">DATA</span></code> and stores remaining lines
from the client in <a class="reference internal" href="#smtpd.SMTPChannel.received_data" title="smtpd.SMTPChannel.received_data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">received_data</span></code></a> until the terminator
<code class="docutils literal notranslate"><span class="pre">&quot;\r\n.\r\n&quot;</span></code> is received.</p></td>
</tr>
<tr class="row-even"><td><p>HELP</p></td>
<td><p>Returns minimal information on command syntax</p></td>
</tr>
<tr class="row-odd"><td><p>VRFY</p></td>
<td><p>Returns code 252 (the server doesn’t know if the address is valid)</p></td>
</tr>
<tr class="row-even"><td><p>EXPN</p></td>
<td><p>Reports that the command is not implemented.</p></td>
</tr>
</tbody>
</table>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> — SMTP Server</a><ul>
<li><a class="reference internal" href="#smtpserver-objects">SMTPServer Objects</a></li>
<li><a class="reference internal" href="#debuggingserver-objects">DebuggingServer Objects</a></li>
<li><a class="reference internal" href="#pureproxy-objects">PureProxy Objects</a></li>
<li><a class="reference internal" href="#mailmanproxy-objects">MailmanProxy Objects</a></li>
<li><a class="reference internal" href="#smtpchannel-objects">SMTPChannel Objects</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="pipes.html"
                        title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code> — Interface to shell pipelines</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="sndhdr.html"
                        title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sndhdr</span></code> — Determine type of sound file</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.10/Doc/library/smtpd.rst"
            rel="nofollow">Show Source
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="sndhdr.html" title="sndhdr — Determine type of sound file"
             >next</a> |</li>
        <li class="right" >
          <a href="pipes.html" title="pipes — Interface to shell pipelines"
             >previous</a> |</li>

          <li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
          <li><a href="https://www.python.org/">Python</a> &#187;</li>
          <li class="switchers">
            <div class="language_switcher_placeholder"></div>
            <div class="version_switcher_placeholder"></div>
          </li>
          <li>
              
          </li>
    <li id="cpython-language-and-version">
      <a href="../index.html">3.10.12 Documentation</a> &#187;
    </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="superseded.html" >Superseded Modules</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> — SMTP Server</a></li>
                <li class="right">
                    

    <div class="inline-search" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
                     |
                </li>
            
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 2001-2025, Python Software Foundation.
    <br />
    This page is licensed under the Python Software Foundation License Version 2.
    <br />
    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
    <br />
    See <a href="/license.html">History and License</a> for more information.<br />
    <br />

    The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
    <br />

    Last updated on August 15, 2025.
    <a href="/bugs.html">Found a bug</a>?
    <br />

    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.3.2.
    </div>

  </body>
</html>