Hooks returning None should make smtp.py behave like nothing happened.
See original GitHub issueWhen hooks are called for each steps of the SMTP call, the code check if the MISSING value is returned, which is an instance of object().
I’m curious to know why.
From my perspective, if a call to a hook returns None, the code should continue like if there were no hooks at all.
The reason behind that is if no response is returned from the hook, the server still has to return a status, and the default one is accepted by the developer.
Moreover, if a hook exists, it MUST implement the logics presents in smtp.py when no hooks exists. Let me explain:
Here’s the line for HELO commands
If there are no hooks, here’s what’s happening:
status = await self._call_handler_hook('HELO', hostname)
if status is MISSING:
self.session.host_name = hostname
status = '250 HELP'
But as soon as I add a HELO handler, the status won’t be MISSING, which means I have to implement the two consequent lines in my own code, by copy/pasting it. That’s not good.
Instead, if the smtp.py code does the following:
status = await self._call_handler_hook('HELO', hostname)
# This expect that the self._call_handler_hook returns also None in case no handler was found
if status is None:
self.session.host_name = hostname
status = '250 HELP'
My handle can return None, saying “everything is good” like all hooks behave, and smtp.py will do the intended work.
But maybe I’m missing a specific reason, so I’d be curious to know.
Otherwise, happy to submit a PR if you want!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
My bad, I did meant #157 😉
I actually have created a branch for this issue: https://github.com/pepoluan/aiosmtpd/tree/treat-none-missing
Originally thought that this can be pushed into 1.4.
But after some thinking, I’ve decided to push this into 2.0 instead, because the changes I made potentially break existing software, and we can’t have that before 2.0.
In the meanwhilst, I can keep tuning this branch.
So, sorry for everyone wanting to see this implemented in the 1.x series: It just won’t happen. You’ll have to import
MISSINGand use that, instead.Feel free to explore my strategy of solving this issue in the branch above. Criticism & discussion is of course welcome.