I too wanted similar functionality, but so that my unit test could be loaded and ran at any time without human intervention (for this particular test). In either case, I began going down the path of sub-classing Python’s smtplib.SMTP class. But reading through the standard python class, some time later, I finally saw that SMTP AUTH is already supported.
I was originally looking for .auth for authenticate, when quite simply the .login method is actually what I needed all along! 🙂
Threw away my new class and begin using SMTP AUTH from the standard python libraries:
srv = smtplib.SMTP('<<server host name>>')
srv.helo('<<originating server host name/ip>>')
srv.sendmail(<<from email>>, <<to email>>, <<email msg>>)
Hope this helps the next Googler…
The small print:
1) I did not compare the differences between ASMTPTest and libsmtp yet. If you do before I get around to it, let me know.
2) There may be other libraries out there like Twisted. But I opted to stick with standard, core, basic libraries that come with a language where ever possible. This makes my unit test suite very portable without having to “set up the dependencies”.