Inbox.py: SMTP for Humans
github.com
github.com
I hope no one uses this in production. Handling SMTP well is all about the edge cases, and this doesn't seem to handle any of them.
This is just a thin wrapper on python stdlib smtpd.SMTPServer, which is itself not production ready. It also doesn't really make it easier. The original API is better. Why are magic decorators better than inheritance again?
Also, monkey patching? Hidden side effects make sad pandas cry. Let me throw up a little in my mouth.
There are zero unit tests for this, and no functional tests.
The original API has better documentation. What are the to, sender, and body arguments?
Below seems a simpler API, and gives you the subject too. I thought humans would be interested in the subject... but I guess not.
import inbox
for m in inbox:
toprint = m.to, m.from, m.subject, m.body
print ("to:{} from:{} subject:{} body:{}".format(toprint))I think the biggest service here is
1. Education about Python's pretty decent standard smtpd lib.
2. Food for thought about making thin custom interfaces over standard libraries.
3. Perhaps inspiration to do more?
It's no Linux kernel, but I enjoyed reading through the source and I feel like I have a better understanding of Python's smtpd lib and I've some of my own ideas for future API design.
Additionally, I like your generator-based API proposal. Also inspiring. Need to think more about routing in that context, though.
SMTP does have many edge cases, and if you're interested in handling all of them, you should use a more robust server. I am not.
> "One instance should handle over one thousand emails per second, thanks to Gevent."
Take a look at the code, it's very small.
Want your app to send some mail? Please please please don't try delivering directly. The only people great at this are spammers. Use a real MTA and the mail() function that is built into basically every language.
edit: I should note that you're correct in that SMTP is used by the client to relay email messages to the server also.
edit: I'm wrong, listen to this guy ->
Our Lamson project has been running for 3 years. It was fun to write, it stays up when we need it to - and it’s easy to modify when we need new features.
This is the only piece of python we have running in-house - we’re a pair of coders and both of us had had very bad experiences with Python (in the distant past - 2002 for me). It’s done quite a lot to rehabilitate python’s reputation here :)
Non-Invenio Hic .. (bad) Latin for "Hack the good hack" ;-)
Looking just at the two examples on the main page, it's an implementation of the SMTP protocol so you can either send mail directly to recipients' servers, or run a mail server.
Sending mail directly is often useful when you need to deliver a message to a lot of recipients. IIRC, this doesn't always work, because many servers reject messages unless they can reverse resolve the ip to the sender's domain.
A server for receiving messages is basic infrastructure. The reason for using a simple solution with clear source code, instead of established daemons, like postfix, is that you can tune it to implement filters or notifications.
As an example: some time ago I had the idea of putting a bayesian spam filter directly in the server code, eliminating the problem of false positives: the mail is either accepted or rejected, in which case the sender gets to know that the message has not arrived its recipient, instead of silently trashing it as spam.
Source: I wrote some of the original SpamAssassin and worked in anti-spam for over 10 years.
https://github.com/kennethreitz/inbox.py/blob/master/inbox.p...
thank you, and keep it up.
Also, both the Inbox constructor and the serve() method takes the listening port and address. Now I need to read the source code in order to figure out where I should put the port number and what happens if I put in two different port numbers. (insert appropriate sort of unhappy smiley)
I believe my feedback to Kenneth (if he even sees this) is that this SMTP server can be even simpler.
The dispatch method is for deferring to cli arguments for external configuration (say, a Procfile).
The constructor is used for defaults.
No dependencies on third party libraries.
I will clean it up and chuck it on bitbucket.org some time this month.
You just publish an endpoint on your app, fire up the service and emails come in as WCF messages ready parsed.
It's pretty fast. One benchmark (by the developer) clocked it at 5000 messages/s on his Macbook.
This particular one isn't so bad, since ".py" is part of the headline, but it's fooled me so many times that it's getting boring. I'm a human. I think SMTP a big hassle. The headline made me think someone somehow reimplemented what SMTP does for us in a modern way. Instead, it's a client library for a programming language that I don't use.
My only regret is that it's for receiving rather than sending. I use ugly wrapper scripts for my most common attachment mailing scenarios right now.