++ed by:
POTATOGIM

1 PAUSE user

Mons Anderson
and 1 contributors

NAME

AnyEvent::SMTP::Server - Simple asyncronous SMTP Server

SYNOPSIS

    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;

DESCRIPTION

Simple asyncronous SMTP server. Authorization not implemented yet. Patches are welcome

FUNCTIONS

smtp_server $host, $port, $cb->(MAIL)

METHODS

new %args;

hosthame

Server FQDN

host

Address to listen on. by default - undef (0.0.0.0)

port

Port to listen on

start

Creates tcp server and starts to listen

stop

Closes all opened connections and shutdown server

EVENTS

ready()

Invoked when server is ready

client($connection)

Invoked when client connects

disconnect($connection)

Invoked when client disconnects

mail($mail)

Invoked when server received complete mail message

    $mail = {
        from => ...,
        to   => [ ... ],
        data => '...',
        host => 'remote addr',
        port => 'remote port',
        helo => 'HELO/EHLO string',
    };

BUGS

Bug reports are welcome in CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-SMTP

AUTHOR

Mons Anderson, <mons at cpan.org>

COPYRIGHT & LICENSE

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.