POE::Component::Server::SMTP - SMTP Protocol Implementation
use POE; use POE::Component::Server::SMTP; POE::Component::Server::SMTP->spawn( Port => 2525, InlineStates => { HELO => \&smtp_helo, QUIT => \&smtp_quit, }, ); sub smtp_helo { my ($heap) = $_[HEAP]; my $client = $heap->{client}; $client->put( SMTP_OK, 'Welcome.' ); } sub smtp_quit { my ($heap) = $_[HEAP]; my $client = $heap->{client}; $client->put( SMTP_QUIT, 'Good bye!' ); $heap->{shutdown_now} = 1; } $poe_kernel->run; exit 0;
POE::Component::Server::TCP implements the SMTP protocol for the server. I won't lie, this is very low level. If you want to support any command other than HELO and QUIT, you'll have to implement it yourself, and define it in your InlineStates, PackageStates, or ObjectStates.
InlineStates
PackageStates
ObjectStates
This module uses POE::Session::MultiDispatch to allow for "Plugins" using PackageStates and ObjectStates.
Also, as of this release, POE version 0.24 is out. This module relies on a CVS version of POE.
This module exports a bunch of constants by default.
SMTP_SYTEM_STATUS SMTP_SYSTEM_HELP SMTP_SERVICE_READY SMTP_QUIT SMTP_OK SMTP_WILL_FORWARD SMTP_CANNOT_VRFY_USER SMTP_START_MAIL_INPUT SMTP_NOT_AVAILABLE SMTP_SERVICE_UNAVAILABLE SMTP_LOCAL_ERROR SMTP_NO_STORAGE SMTP_SYNTAX_ERROR SMTP_ARG_SYNTAX_ERROR SMTP_NOT_IMPLEMENTED SMTP_BAD_SEQUENCE SMTP_ARG_NOT_IMPLEMENTED SMTP_UNAVAILABLE SMTP_USER_NOT_LOCAL SMTP_QUOTA_LIMIT SMTP_MAILBOX_ERROR SMTP_NO_SERVICE SMTP_TRANSACTION_FAILED
If you don't know what these mean, see the source.
Create a new instance of the SMTP server. The argument list follows.
The alias name for this session.
The address to bind to. If you don't do this you run the risk of becomming a relay.
The host name to use when identifying the SMTP server.
The port to listen and accept connections on.
Passed directly to POE::Session::MultiDispatch.
There are only three builtin events. This way, the default POE::Component::Server::SMTP distribution is completley secure. Unless otherwise noted, event names corrispond to the uppercase version of the verb supplied from the client during an SMTP connection (HELO, VRFY, RCPT).
Any input supplied after the command verb will be available to the event handler in $_[ARG1], the command name itself is available in $_[ARG0].
$_[ARG1]
$_[ARG0]
This event is triggered when a client connects and it's time to send a banner. This can be supplied in your own send_banner event in your InlineStates.
send_banner
This event is triggered when a client sends a HELO command. This can be supplied in your own HELO event in your InlineStates.
HELO
This event is triggered when a client sends a QUIT command. This can be supplied in your own QUIT event in your InlineStates.
QUIT
This event should always set $heap-{shutdown_now}> to a true value.
$heap-
In the source of this module there are two example handlers for handling the DATA event. The DATA event is kind of tricky, so refer to the smtpd_DATA and smtpd_gotDATA subroutines in the source.
DATA
smtpd_DATA
smtpd_gotDATA
This event is called when the client disconnects. Specifically, when POE::Component::Server::TCP throws the ClientDisconnected state. You can't always rely on an SMTP client calling QUIT, so use this for garbage collection or handling an unexpected end of session.
ClientDisconnected
Any event that it triggered from the client that the server doesn't know how to handle will be passed to the _default handler. This handler will return SMTP_NOT_IMPLEMENTED, unless you override it using InlineStates and do something else.
_default
SMTP_NOT_IMPLEMENTED
No doubt.
It should be noted that this is extremley early code. After all, it relies on features of POE that haven't even been released. Anything could change!
See http://rt.cpan.org to report bugs.
The following is what I would consider known issues.
The only way to override builtin event handlers is using InlineStates. The truth is that there probably shouldn't be any builtin handlers. They will probably go away soon.
Documentation and Tests are lacking.
There is no POE::Component::Client::SMTP yet, though that's really a TODO item.
Casey West <casey@geeknest.com>
Meng Wong, and http://pobox.com/
Copyright (c) 2003 Casey West. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl, POE.
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install POE::Filter::SMTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Filter::SMTP
CPAN shell
perl -MCPAN -e shell install POE::Filter::SMTP
For more information on module installation, please visit the detailed CPAN module installation guide.