Saw this on Freshmeat myself, and thought it good enough to share. A lone monk unlike ourselves has written an SMTP server in Perl. The URL is http://members.xoom.com/jakillen/perlsmtp.html and you can pull the code and a config file from there.

EDIT: xoom.com no longer exists.

Replies are listed 'Best First'.
RE: An SMTP server in Perl
by SuperCruncher (Pilgrim) on Jul 30, 2000 at 19:06 UTC
    Very impressive - that's what you call lightweight - it uses around 22 kb disk space in total!

    I had to hack it a bit to get it to work on Win32, and even then it behaved slightly strangely. I had to comment out:

    if((getpwuid($>))[0] ne "root") { # how is this handled on Microsoft +systems? print STDERR "You are ", (getpwuid($>))[0], " and $0 must be run a +s root.\n"; exit(1); }
    as my version of Perl doesn't implement getpwuid().

    Then when I ran it I got this warning:

    readline() on closed filehandle main::ALIASES at smtp.pl line 77.
    . I first tried telnetting to it, then I couldn't remember all the commands (just tried HELO foo) and then quit the telnet prog).

    Boy, smtp.pl didn't like that! I got tons of warnings:

    Use of uninitialized value in exists at smtp.pl line 107, <GEN1> line +1. Use of uninitialized value in chomp at smtp.pl line 100, <GEN1> line 1 +. Use of uninitialized value in substitution (s///) at smtp.pl line 101, + <GEN1> l
    etc., you get the idea!

    But, it did send e-mail. Very nice little script.

RE: An SMTP server in Perl
by DrManhattan (Chaplain) on Aug 01, 2000 at 23:28 UTC

    Neat! I have to cringe as I read the source code though. There are only 19 commented lines out of 826! Also, it wasn't written with security in mind. For instance, if I have ftp access to an account on a machine running smtp.pl, I can execute arbitrary shell commands by uploading a file to my home directory named ".perlsmtp" containing the line "maildeliver = |/do/whatever".

    Here's another thing that jumped out at me:

    open(CONFIG, $_[0]) or die "Could not open config file $_[0]\n";

    Randal would call this "running with scissors". You should always, always, always specify a mode for open(). E.g.:

    open(CONFIG, "<$_[0]") or die "Could not open config file $_[0]\n" +;

    Otherwise you run the risk of a malicious user sneaking a value like "|rm -rf /home" into the filename. The above example isn't exploitable in the smtp script, mind you, but seeing that, I have to wonder what other bad habits might be lurking in the other 825 lines.

    -Matt

RE: An SMTP server in Perl
by gaggio (Friar) on Jul 31, 2000 at 00:56 UTC
    I'm sorry my post did not make it to The Monastery Gates, but you can find it right there. It is about Ultimail.pm, a module I wrote to send emails without your ISP's mailserver.

    Ultimail.pm is *not* similar to this SMTP daemon, since you actually use this daemon as a SMTP server, whereas you use Ultimail.pm as a replacement of Mail::Sender (for example), when you do not want to have to specify a mailserver to forward your email (Ultimail.pm talks directly to the target SMTP server).

    I must say that there exist already a module called Net::SMTP (click a second time to search on CPAN), which is supposed to work the same way as the daemon presented here (although everytime I tried to use Net::SMTP on Win32 it failed (program hanged - doing nothing) - and I see that somebody got this daemon to work under Win32).