Simple SMTP server

When I was testing the SMTP client on the routers (configured with action … mail command or as part of EEM SMTP library), I didn't want the messages with weird addresses and content to circulate through our e-mail system (plus I wanted to see the results immediately), so I wrote a simple SMTP server in Perl that prints the messages it receives. It accepts a single parameter: the IP address to listen on (only needed on workstations with multiple IP addresses).

You need the Net::SMTP::Server module on top of the standard Perl distribution to make it work.

You can download the PERL source code or compiled EXE file (for Windows users) from CT3 wiki.

8 comments:

  1. Why not simply listen on 0.0.0.0 (any) IP address instead of resolving hostname to IP address of one interface?

    ReplyDelete
  2. Right. 0.0.0.0. Maybe because the router also has external-facing interfaces, and Ivan doesn't want to become a free relay for SPAM ? :)

    Listening on 0.0.0.0 is asking for trouble. bind to 127.0.0.1 if no need to accept outside connections. bind to specific interfaces otherwise. But try to avoid 0.0.0.0 ;)

    ""be conservative in what you generate, and liberal in what you accept.""

    Going back to the SMTP "basic server" - I've had good results using the Mercury Mail MTA - since 1999, my "ligthweight mail server of choice for lab-related stuff" - http://www.pmail.com/overviews/ovw_mercury.htm

    ReplyDelete
  3. Great bluedaemon. But this is lab - the server would be running on workstation/laptop, not on a router. The server is only capable to dump incoming mail on standard output, not to store or relay them.

    ReplyDelete
  4. My sample session

    220 MacGyver SMTP Ready.
    helo localhost
    250 You're polite.
    mail from: <>
    250 Ok...got it.
    rcpt to: <>
    250 Ok...got it.
    data
    354 Give it to me, big daddy.
    From: <>
    To: <>
    Subject: aaa

    test
    .
    250 I got it darlin'.
    quit
    221 Good.

    give me odd result

    Waiting for incoming SMTP connections on localhost
    Incoming mail ...received
    From: <>
    To: ARRAY(0xb6eb90)

    From: <>
    To: <>
    Subject: aaa

    test


    The question is: what is ARRAY(0xb6eb90) ?

    ReplyDelete
  5. @anonymous(1): You can always run it with smtpDump.pl 0.0.0.0. You can also change the default behavior by replacing hostname with "0.0.0.0" in line 6 of the code.

    @bluedemon: Thanks for the Mercury Mail MTA tip. Exactly what I've been looking for during the last few months.

    @anonymous(4): Thanks for the bug report, I've fixed the code.

    ReplyDelete
  6. Zip file from your site still contains buggy version. The compiled version is very handy for me. Please fix it.

    ReplyDelete
  7. @Anonymous(5): Uploaded the fixed code in zip file.

    ... and why don't you guys choose some unique identifier (just select "Other" in the identity field and type in whatever you feel like), this "anonymous(N+1)" stuff is getting tedious :(

    ReplyDelete
  8. This version works pretty well. Thank you.

    ReplyDelete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.