5 use vars qw(%aliases $opt_d $opt_a);
6 use subs qw(validate_recipient process_message read_aliases);
7 use Net::Server::Mail::ESMTP;
11 my $smtp = new Net::Server::Mail::ESMTP;
12 $smtp->set_callback(RCPT => \&validate_recipient);
13 $smtp->set_callback(DATA => \&process_message);
20 sub validate_recipient {
21 my($session, $recipient) = @_;
23 $recipient =~ s/\@.*$//;
24 return(0, 550, "Unknown user $recipient") unless exists $aliases{$recipient};
29 my($session, $data) = @_;
31 #warn "DATA: ". $$data;
33 my @recipients = $session->get_recipients();
34 return(0, 554, 'Error: no valid recipients')
37 foreach my $recipient ( @recipients ) {
39 $recipient =~ s/\@.*$//;
41 open(PIPE, '|'.$aliases{$recipient})
42 or return(0, 451, "Can't fork: $!" );
44 or return(0, 451, "Can't write to pipe: $!" );
46 or return(0, 451, "Can't close: status=$?" );
50 return(1, 250, 'message piped');
57 open(ALIASES, $opt_a || '/etc/aliases' ) or die $!;
63 /^([\w\-\+\.]+):\s*("?)\|(.*)\2\s*$/ or next;
64 #$aliases{$1} = [ split(/\s+/, $3) ];
72 _smtpd - UnderSMTPD, the underscore SMTP daemon
77 echo 'username: "|someprogram and args" > /etc/aliases
80 echo "smtp stream tcp nowait mail /usr/local/bin/_smtpd" >>/etc/inetd.conf
81 echo "_smtpd: my.mail.server.ip" >>/etc/hosts.allow
82 echo "_smtpd: ALL" >>/etc/hosts.deny
84 #or add an smtp file to /etc/xinetd.d/
91 server = /usr/local/bin/_smtpd
96 This is a minimal SMTP server which only forwards mail to pipe destinations
97 in /etc/aliases. It does nothing else. Its intended function is on an
98 internal mail server that forwards mail to other programs on a per address
101 UnderSMTPD reads /etc/aliases for usernames; if a match is identified
102 the message is piped to the given program. Any problems executing the program
103 will cause a temporary SMTP error to be returned to the connecting client.
105 Other kinds of aliases are not recognized and cause a perminant SMTP error
106 to be returned to the connecting client, as do usernames not found in
109 UnderSMTP was originally written to be used with the Request Tracker ticketing
112 UnderSMTP uses Net::SMTP::Mail to do all the hard work.
118 =item -a filename: Alternate aliases file
120 =head1 ALIASES FORMAT
122 username: |program and args
123 username: "|program and args"
125 Quotes are not necessary around the pipe symbol, program and arguments but are
126 stripped if present. Line continuations are not supported.
128 =head1 RT ALIASES EXAMPLE
130 support: |/opt/rt3/bin/rt-mailgate --queue support --action correspond --url http://rt.example.com/
131 billing: |/opt/rt3/bin/rt-mailgate --queue billing --action correspond --url http://rt.example.com/
139 Ivan Kohler <ivan-undersmtpd@420.am>