It's my first...

I've just released my first β€˜serious’ open source software project into the public! πŸŽ‰

It's Purepythonmilter – a pure-Python Milter framework. If you're operating your own mail server or developing software in the field of email, you may be interested in this. πŸ“¨

Purepythonmilter aims to be a modern, Postfix-first, high-quality, strictly typed framework and library. And then all of that with an easy to use API and a high-performance asynchronous embedded server to point Postfix to.

What is a Milter? πŸ€”

Mail servers (MTAs) like Postfix and Sendmail can connect to an external filter process, called a 'Milter', for actions to take during an incoming SMTP transaction. You may consider it like a plugin on the mail server software using callbacks over a TCP or UNIX socket.

An very much simplified example using Purepythonmilter:

# pip install purepythonmilter
import purepythonmilter as ppm


async def on_mail_from(cmd: ppm.MailFrom) -> ppm.VerdictOrContinue:
    """
    Block all mail with a sender address (envelope-from) on the example.com domain.
    """
    if cmd.address.lower().endswith("@example.com"):
        return ppm.RejectWithCode(primary_code=(5, 7, 1), text="not allowed here!")
    return ppm.Continue()


mymilter = ppm.PurePythonMilter(name="mymilter", hook_on_mail_from=on_mail_from)
# Configure Postfix with 'smtpd_milters = inet:127.0.0.1:9000'
mymilter.run_server(host="127.0.0.1", port=9000)

Just run this as Python file and it just works – press Ctrl+C to shut it down gracefully. βœ…

More examples are provided in the repository to get started and include instructions to test your app with Postfix in Docker. 🐳

Why this project?

Purepythonmilter was written as an alternative to, and, out of frustration with PyMilter. PyMilter is not type annotated (mypy), has signal handling issues (for me), the dependency on a hand-crafted Python-C-extension linking to Sendmail's libmilter and no offering of a binary package (wheel) to ease installation. πŸ˜₯

The aforementioned example above takes a lot more lines of code to get running using PyMilter with its subclassing-style API as well.

Apart from these issues I have some concerns on the overall software quality of existing projects and I want to gain more experience in writing async Python applications. πŸ˜ƒ

Purepythonmilter may be far from a stable release, but it has ~ 95% test coverage and validates 100% with mypy 1.0.0 in strict mode to deserve a solid start. πŸš€

Feedback requested πŸ’¬

Please check out the GitHub page, install it from PyPI and let me know what you think in the discussions, via Twitter or email!

It's Apache-2.0-licensed allowing you to use it in a commercial setting as well.

Share on: Twitter ❄ Hacker News ❄ Facebook ❄ LinkedIn ❄ Reddit ❄ Email

Comments

comments powered by Disqus

Related Posts


Published

Category

Programming

Tags

Connect with me on...