|
NAMENet::Server::Mail::SMTP - A module to implement the SMTP protocolSYNOPSISuse Net::Server::Mail::SMTP; my @local_domains = qw(example.com example.org); my $server = IO::Socket::INET->new( Listen => 1, LocalPort => 25 ); my $conn; while($conn = $server->accept) { my $smtp = Net::Server::Mail::SMTP->new( socket => $conn ); $smtp->set_callback(RCPT => \&validate_recipient); $smtp->set_callback(DATA => \&queue_message); $smtp->process(); $conn->close(); } sub validate_recipient { my($session, $recipient) = @_; my $domain; if($recipient =~ /\@(.*)>\s*$/) { $domain = $1; } if(not defined $domain) { return(0, 513, 'Syntax error.'); } elsif(not(grep $domain eq $_, @local_domains)) { return(0, 554, "$recipient: Recipient address rejected: Relay access denied"); } return(1); } sub queue_message { my($session, $data) = @_; my $sender = $session->get_sender(); my @recipients = $session->get_recipients(); return(0, 554, 'Error: no valid recipients') unless(@recipients); my $msgid = add_queue($sender, \@recipients, $data) or return(0); return(1, 250, "message queued $msgid"); } DESCRIPTIONThis class implement the SMTP (RFC 821) protocol. Notice that it don't implement the extension mechanism introduce in RFC 2821. You have to use Net::Server::Mail::ESMTP if you want this capability.This class inherit from Net::Server::Mail. Please see Net::Server::Mail for documentation of common methods. METHODSSMTP specific methods.get_senderReturns the sender of the current session. Return undefined if the reverse path step is not complete.get_recipientsReturns the list of recipients supplied by client. Returns undef if forward_path step is not engaged. Returns an empty list if not recipients succeed.EVENTSDescriptions of callback who's can be used with set_callback method. All handle takes the Net::Server::Mail::SMTP object as first argument and specific callback's arguments.HELOTakes the hostname given as argument. Engage the reverse path step on success.sub helo_handle { my($session, $hostname) = @_; if($hostname eq 'localhost') { return(0, 553, q(I don't like this hostname, try again.)); } # don't forgot to return a success reply if you are happy with # command's value return 1; } NOOPThis handler takes no argumentEXPNCommand not yet implemented.Handler takes address as argument. EXPNCommand not implemented, deprecated by RFC 2821Handler takes no argument. VRFYCommand not yet implemented.Handler takes address as argument. HELPCommand not yet implemented.Handler takes a command name as argument. RCPTHandler takes address as argument. On success, engage the mail data path step and push the given address into the recipient list for later use (get it with get_recipients() method).SENDCommand not implemented.Handler takes no argument. SOMLCommand not implemented.Handler takes no argument. SAMLCommand not implemented.Handler takes no argument. DATAThis handler is called after the final . sent by client. It takes data as argument in a scalar reference. You should queue the message and reply with the queue ID.DATA-INITThis handler is called before enter in the "waiting for data" step. The default success reply is a 354 code telling the client to send the mail content.DATA-PARTThis handler is called at each parts of mail content sent. It takes as argument a scalar reference to the part of data received. It is deprecated to change the contents of this scalar.RSETHandler takes no argument.On success, all step are initialized and sender/recipients list are flushed. QUITHandler takes no argument.Connection is closed after this command. This behavior may change in future, you will probably be able to control the closing of connection. SEE ALSOPlease, see Net::Server::Mail, Net::Server::Mail::ESMTP and Net::Server::Mail::LMTP.AUTHOROlivier Poitrey <rs@rhapsodyk.net>AVAILABILITYAvailable on CPAN.anonymous Git repository: git clone git://github.com/rs/net-server-mail.git Git repository on the web: <https://github.com/rs/net-server-mail> BUGSPlease use CPAN system to report a bug (http://rt.cpan.org/).LICENCEThis library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA COPYRIGHTCopyright (C) 2002 - Olivier Poitrey, 2007 - Xavier Guimard
Visit the GSP FreeBSD Man Page Interface. |