AnyEvent::SMTP::Server - Simple asyncronous SMTP Server
use AnyEvent::SMTP::Server 'smtp_server'; smtp_server undef, 2525, sub { my $mail = shift; warn "Received mail from $mail->{from} to $mail->{to}\n$mail->{data}\n"; }; # or use AnyEvent::SMTP::Server; my $server = AnyEvent::SMTP::Server->new( port => 2525, mail_validate => sub { my ($m,$addr) = @_; if ($good) { return 1 } else { return 0, 513, 'Bad sender.' } }, rcpt_validate => sub { my ($m,$addr) = @_; if ($good) { return 1 } else { return 0, 513, 'Bad recipient.' } }, data_validate => sub { my ($m,$data) = @_; my $size = length $data; if ($size > $max_email_size) { return 0, 552, 'REJECTED: message size limit exceeded'; } else { return 1; } }, ); $server->reg_cb( client => sub { my ($s,$con) = @_; warn "Client from $con->{host}:$con->{port} connected\n"; }, disconnect => sub { my ($s,$con) = @_; warn "Client from $con->{host}:$con->{port} gone\n"; }, mail => sub { my ($s,$mail) = @_; warn "Received mail from ($mail->{host}:$mail->{port}) $mail->{from} to $mail->{to}\n$mail->{data}\n"; }, ); $server->start; AnyEvent->condvar->recv;
Simple asyncronous SMTP server. Authorization not implemented yet. Patches are welcome
Server FQDN
Address to listen on. by default - undef (0.0.0.0)
Port to listen on
Creates tcp server and starts to listen
Closes all opened connections and shutdown server
Invoked when server is ready
Invoked when client connects
Invoked when client disconnects
Invoked when server received complete mail message
$mail = { from => ..., to => [ ... ], data => '...', host => 'remote addr', port => 'remote port', helo => 'HELO/EHLO string', };
Bug reports are welcome in CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-SMTP
Mons Anderson, <mons at cpan.org>
<mons at cpan.org>
Copyright 2009 Mons Anderson, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install AnyEvent::SMTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::SMTP
CPAN shell
perl -MCPAN -e shell install AnyEvent::SMTP
For more information on module installation, please visit the detailed CPAN module installation guide.