• Stars
    star
    318
  • Rank 131,070 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated 23 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A reimplementation of the Python stdlib smtpd.py based on asyncio.

aiosmtpd - An asyncio based SMTP server

Project License on GitHub PyPI Package Supported Python Versions Supported Python Implementations
GitHub CI status  CodeQL status  Code Coverage Documentation Status

GitHub Discussions

The Python standard library includes a basic SMTP server in the smtpd module, based on the old asynchronous libraries asyncore and asynchat. These modules are quite old and are definitely showing their age; asyncore and asynchat are difficult APIs to work with, understand, extend, and fix. (And have been deprecated since Python 3.6, and will be removed in Python 3.12.)

With the introduction of the asyncio module in Python 3.4, a much better way of doing asynchronous I/O is now available. It seems obvious that an asyncio-based version of the SMTP and related protocols are needed for Python 3. This project brings together several highly experienced Python developers collaborating on this reimplementation.

This package provides such an implementation of both the SMTP and LMTP protocols.

Full documentation is available on aiosmtpd.readthedocs.io

Requirements

You need at least Python 3.7 to use this library.

Supported Platforms

aiosmtpd has been tested on CPython>=3.7 and PyPy>=3.7 for the following platforms (in alphabetical order):

  • Cygwin (as of 2022-12-22, only for CPython 3.7, 3.8, and 3.9)
  • MacOS 11 and 12
  • Ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • Windows 10
  • Windows Server 2019
  • Windows Server 2022

aiosmtpd probably can run on platforms not listed above, but we cannot provide support for unlisted platforms.

Installation

Install as usual with pip:

pip install aiosmtpd

If you receive an error message ModuleNotFoundError: No module named 'public', it likely means your setuptools is too old; try to upgrade setuptools to at least version 46.4.0 which had implemented a fix for this issue.

Project details

As of 2016-07-14, aiosmtpd has been put under the aio-libs umbrella project and moved to GitHub.

The best way to contact the developers is through the GitHub links above. You can also request help by submitting a question on StackOverflow.

Building

You can install this package in a virtual environment like so:

$ python3 -m venv /path/to/venv
$ source /path/to/venv/bin/activate
$ python setup.py install

This will give you a command line script called aiosmtpd which implements the SMTP server. Use aiosmtpd --help for a quick reference.

You will also have access to the aiosmtpd library, which you can use as a testing environment for your SMTP clients. See the documentation links above for details.

Developing

You'll need the tox tool to run the test suite for Python 3. Once you've got that, run:

$ tox

Individual tests can be run like this:

$ tox -- <testname>

where <testname> is the "node id" of the test case to run, as explained in the pytest documentation. The command above will run that one test case against all testenvs defined in tox.ini (see below).

If you want test to stop as soon as it hit a failure, use the -x/--exitfirst option:

$ tox -- -x

You can also add the -s/--capture=no option to show output, e.g.:

$ tox -e py37-nocov -- -s

and these options can be combined:

$ tox -e py37-nocov -- -x -s <testname>

(The -e parameter is explained in the next section about 'testenvs'. In general, you'll want to choose the nocov testenvs if you want to show output, so you can see which test is generating which output.)

Supported 'testenvs'

In general, the -e parameter to tox specifies one (or more) testenv to run (separate using comma if more than one testenv). The following testenvs have been configured and tested:

  • {py37,py38,py39,py310,py311,pypy3,pypy37,pypy38,pypy39}-{nocov,cov,diffcov,profile}

    Specifies the interpreter to run and the kind of testing to perform.

    • nocov = no coverage testing. Tests will run verbosely.
    • cov = with coverage testing. Tests will run in brief mode (showing a single character per test run)
    • diffcov = with diff-coverage report (showing difference in coverage compared to previous commit). Tests will run in brief mode
    • profile = no coverage testing, but code profiling instead. This must be invoked manually using the -e parameter

    Note 1: As of 2021-02-23, only the {py37,py38,py39}-{nocov,cov} combinations work on Cygwin.

    Note 2: It is also possible to use whatever Python version is used when invoking tox by using the py target, but you must explicitly include the type of testing you want. For example:

    $ tox -e "py-{nocov,cov,diffcov}"
    

    (Don't forget the quotes if you want to use braces!)

    You might want to do this for CI platforms where the exact Python version is pre-prepared, such as Travis CI or GitHub Actions; this will definitely save some time during tox's testenv prepping.

    For all testenv combinations except diffcov, bandit security check will also be run prior to running pytest.

  • qa

    Performs flake8 code style checking, and flake8-bugbear design checking.

    In addition, some tests to help ensure that aiosmtpd is releasable to PyPI are also run.

  • docs

    Builds HTML documentation and manpage using Sphinx. A pytest doctest will run prior to actual building of the documentation.

  • static

    Performs a static type checking using pytype.

    Note 1: Please ensure that all pytype dependencies have been installed before executing this testenv.

    Note 2: This testenv will be _SKIPPED_ on Windows, because pytype currently cannot run on Windows.

    Note 3: This testenv does NOT work on Cygwin.

Environment Variables

ASYNCIO_CATCHUP_DELAY

Due to how asyncio event loop works, some actions do not instantly get responded to. This is especially so on slower / overworked systems. In consideration of such situations, some test cases invoke a slight delay to let the event loop catch up.

Defaults to 0.1 and can be set to any float value you want.

Different Python Versions

The tox configuration files have been created to cater for more than one Python versions safely: If an interpreter is not found for a certain Python version, tox will skip that whole testenv.

However, with a little bit of effort, you can have multiple Python interpreter versions on your system by using pyenv. General steps:

  1. Install pyenv from https://github.com/pyenv/pyenv#installation

  2. Install tox-pyenv from https://pypi.org/project/tox-pyenv/

  3. Using pyenv, install the Python versions you want to test on

  4. Create a .python-version file in the root of the repo, listing the Python interpreter versions you want to make available to tox (see pyenv's documentation about this file)

    Tip: The 1st line of .python-version indicates your preferred Python version which will be used to run tox.

  5. Invoke tox with the option --tox-pyenv-no-fallback (see tox-pyenv's documentation about this option)

housekeep.py

If you ever need to 'reset' your repo, you can use the housekeep.py utility like so:

$ python housekeep.py superclean

It is strongly recommended to NOT do superclean too often, though. Every time you invoke superclean, tox will have to recreate all its testenvs, and this will make testing much longer to finish.

superclean is typically only needed when you switch branches, or if you want to really ensure that artifacts from previous testing sessions won't interfere with your next testing sessions.

For example, you want to force Sphinx to rebuild all documentation. Or, you're sharing a repo between environments (say, PSCore and Cygwin) and the cached Python bytecode messes up execution (e.g., sharing the exact same directory between Windows PowerShell and Cygwin will cause problems as Python becomes confused about the locations of the source code).

Signing Keys

Starting version 1.3.1, files provided through PyPI or GitHub Releases will be signed using one of the following GPG Keys:

GPG Key ID Owner Email
5D60 CE28 9CD7 C258 Pandu E POLUAN pepoluan at gmail period com
5555 A6A6 7AE1 DC91 Pandu E POLUAN pepoluan at gmail period com
E309 FD82 73BD 8465 Wayne Werner waynejwerner at gmail period com

License

aiosmtpd is released under the Apache License version 2.0.

More Repositories

1

aiohttp

Asynchronous HTTP client/server framework for asyncio and Python
Python
14,457
star
2

aiomysql

aiomysql is a library for accessing a MySQL database from the asyncio
Python
1,721
star
3

aiopg

aiopg is a library for accessing a PostgreSQL database from the asyncio
Python
1,369
star
4

yarl

Yet another URL library
Python
1,200
star
5

aiobotocore

asyncio support for botocore library using aiohttp
Python
1,163
star
6

aiokafka

asyncio client for kafka
Python
1,093
star
7

aiocache

Asyncio cache manager for redis, memcached and memory
Python
1,032
star
8

aiojobs

Jobs scheduler for managing background task (asyncio)
Python
820
star
9

janus

Thread-safe asyncio-aware queue for Python
Python
774
star
10

aiohttp-demos

Demos for aiohttp project
Makefile
705
star
11

async-lru

Simple LRU cache for asyncio
Python
695
star
12

aiomonitor

aiomonitor is module that adds monitor and python REPL capabilities for asyncio application
Python
644
star
13

async-timeout

asyncio-compatible timeout class
Python
536
star
14

aiozmq

Asyncio (pep 3156) integration with ZeroMQ
Python
420
star
15

aiodocker

Python Docker API client based on asyncio and aiohttp
Python
417
star
16

multidict

The multidict implementation
Python
386
star
17

create-aio-app

The boilerplate for aiohttp. Quick setup for your asynchronous web service.
Python
306
star
18

aioodbc

aioodbc - is a library for accessing a ODBC databases from the asyncio
Python
304
star
19

aiohttp-devtools

dev tools for aiohttp
Python
248
star
20

aiohttp-session

Web sessions for aiohttp.web
Python
238
star
21

aiohttp-security

auth and permissions for aiohttp
Python
229
star
22

aiohttp-jinja2

jinja2 template renderer for aiohttp.web
Python
228
star
23

aiohttp-admin

admin interface for aiohttp application http://aiohttp-admin.readthedocs.io
Python
216
star
24

aiohttp-cors

CORS support for aiohttp
Python
199
star
25

aiohttp-sse

Server-sent events support for aiohttp
Python
197
star
26

aiohttp-debugtoolbar

aiohttp_debugtoolbar is library for debugtoolbar support for aiohttp
JavaScript
193
star
27

aiozipkin

Distributed tracing instrumentation for asyncio with zipkin
Python
184
star
28

aioftp

ftp client/server for asyncio (http://aioftp.readthedocs.org)
Python
183
star
29

aioelasticsearch

aioelasticsearch-py wrapper for asyncio
Python
139
star
30

aiomcache

Minimal asyncio memcached client
Python
139
star
31

aiosignal

aiosignal: a list of registered asynchronous callbacks
Python
130
star
32

pytest-aiohttp

pytest plugin for aiohttp support
Python
129
star
33

aiorwlock

Read/Write Lock - synchronization primitive for asyncio
Python
129
star
34

sockjs

SockJS Server
Python
118
star
35

frozenlist

`FrozenList` is a `list`-like structure that implements `collections.abc.MutableSequence` and can be made immutable.
Python
95
star
36

aiocassandra

Simple threaded cassandra wrapper for asyncio
Python
88
star
37

aiohttp-remotes

A set of useful tools for aiohttp.web server
Python
80
star
38

aiologstash

asyncio logging handler for logstash
Python
58
star
39

aiocouchdb

CouchDB client built on top of aiohttp (asyncio)
Python
53
star
40

aioamqp_consumer

consumer/producer/rpc library built over aioamqp
Python
36
star
41

aiohttp-mako

mako template renderer for aiohttp.web
Python
31
star
42

aioneo4j

asyncio client for neo4j
Python
30
star
43

aiosparql

An asynchronous SPARQL client library using aiohttp
Python
25
star
44

sort-all

Sort __all__ lists alphabetically
Python
25
star
45

aioga

Google Analytics client for asyncio
Python
22
star
46

aioppspp

IETF PPSP RFC7574 in Python/asyncio
Python
21
star
47

sphinxcontrib-asyncio

Sphinx extension to add asyncio-specific markups
Python
20
star
48

aiohttp-benchmarks

Python
17
star
49

aioloop-proxy

A proxy for asyncio.AbstractEventLoop for testing purposes
Python
14
star
50

aiohttp-flashbag

The library provides flashbag for aiohttp
Python
10
star
51

idna-ssl

Patch ssl.match_hostname for Unicode(idna) domains support
Python
9
star
52

aiohttp-bot

A bot for automating boring tasks
Python
8
star
53

aio-libs.github.io

aio-libs static site
HTML
8
star
54

dynoname

Dynamic name resolution for asyncio libraries
Python
8
star
55

.github

Organization wide community settings
Python
7
star
56

triagers

A repo for request for aio-libs triage
5
star
57

get-releasenote

GitHub action for getting release note from towncrier rendered file
Python
5
star
58

aiohappyeyeballs

Happy Eyeballs for pre-resolved hosts
Python
5
star
59

create-release

GitHub action for release creation
4
star
60

aiohttp-site

A site for aiohttp project
HTML
3
star
61

prepare-coverage

Temporarily store coverage in Artifact storage
Makefile
3
star
62

aiohttp-theme

Sphinx theme for aiohttp
Python
2
star
63

azure-pipelines

Common azure pipelines templates used by aio-libs
2
star
64

night-watch

Ops purposes repo: validates Travis CI configs of all the repos in @aio-libs on daily basis
2
star
65

upload-coverage

Upload coverage chunks previously stored by prepare-coverage action
Makefile
1
star