in reply to Re: SMTP logging server
in thread SMTP logging server

no, i don't care to reject any mail. I just want to log the addressee and the timestamp. All I really want to do is test another SMTP server ( a real one) by sending test messages to an "email sink" whose only job is logging. Therefore, I want something light and independent--and as simple as possible.

Do you think I should use forking and/or threading? (I though threads did not work properly in perl). Also, it would be nice if this SMTP daemon could be run on linux AND Windows. I though Perl would be the perfect choice for such a simple endeavor (I just need to figure out how SMPT works).

Thanx

Replies are listed 'Best First'.
RE: RE: Re: SMTP logging server
by cianoz (Friar) on Oct 19, 2000 at 03:06 UTC
    i wrote this in 10 minutes
    (here in italy is night and i've got a good bottle of wine in front of me ;)))
    stupid as you whant but fools netscape messanger :)
    I used NetServer::Generic since is too late for me to mess with sockets...
    #!/usr/bin/perl -w use strict; use NetServer::Generic; my $server = new NetServer::Generic; $server->port(25); $server->callback(\&server); $server->timeout(25); ## random... $server->run(); sub server { open LOG, ">>/tmp/smtpd.log" || die "cannot open: $!"; print LOG "\nNew connection\n-------------\n"; print "220 mydomail.com ESMTP CianozMail 0.1 :)\n"; while(<STDIN>) { print LOG "$_"; if($_ =~ /^quit\r\n/i ) { print "221 Bye\n"; close LOG; return; } elsif($_ =~ /^data/i ) { ## read message body here... print "354 End data with <CR><LF>.<CR><LF>\n"; MESSAGE: while(my $line = <STDIN>) { if($line =~ /^\.\r\n/) { print "250 Ok: queued as ....\n"; last MESSAGE; } else { print LOG "$line"; } } } else { print "250 Ok\n"; #who cares? :-) } } }
      I think the original poster would rather be looking for the line: RCPT TO: youraddy@someplace.com And then just record the e-mail address here. This would just be one more branch in your code. Also, I'm a newbie, but shouldn't you be recording all the log information at one time? To prevent two clients from writing to the log at the same time.
        You are right, the code should also flock() the log file or a sentinel file and maybe do a lot more things off course... my code was just a trivial example...