smtp_toolkit

Speaking SMTP to mail servers with Python!

In my daily work, I often find the need to test various mail servers: verify that they are responding, see if they support TLS, check what the max supported message size is, etc. This is usually an exercise in running a telnet session to port 25 of the mail server and inspecting from there.

Seeing as telnet isn’t installed by default on some operating systems these days (I’m looking at you Windows 7), writing a Python class seemed to be the right thing to do. I can incorporate it in to scripts, schedule checks, work it into mxutils.com… The list goes on.

It’s pretty straightforward to use, and I’ve made the code available under the BSD license at http://github.com/polera/smtp_toolkit.

Here are some basic examples of usage:

 1 from smtp_toolkit import SMTPServerTest
 2 
 3     # setup a list of servers to check
 4     server_list = ['smtp.gmail.com']
 5   
 6     for server in server_list:
 7       print(server)
 8       s = SMTPServerTest(server)
 9       # server connection results are returned as a dict
10       print(s.results)
11       # get the EHLO options (i.e. what would be returned after an ehlo command)
12       print("EHLO options %s" % ", ".join(s.ehlo_options))
13       # see if the server supports TLS (based on the EHLO response)
14       print("TLS Supported? %s" % s.server_supports_tls)
15       # what is the max message size that this server will handle (also from EHLO)
16       print("Max message size: %d MB" % s.server_max_message_size)

I plan on building this out to support more features in the near future, so if you’re interested, keep an eye on the github repo.

Now, go test your servers!

Comments