++ed by:
POTATOGIM

1 PAUSE user

Mons Anderson
and 1 contributors

NAME

AnyEvent::SMTP::Client - Simple asyncronous SMTP Client

SYNOPSIS

    use AnyEvent::SMTP::Client 'sendmail';
    
    sendmail
        from => 'mons@cpan.org',
        to   => 'mons@cpan.org', # SMTP host will be detected from addres by MX record
        data => 'Test message '.time().' '.$$,
        cb   => sub {
            if (my $ok = shift) {
                warn "Successfully sent";
            }
            if (my $err = shift) {
                warn "Failed to send: $err";
            }
        }
    ;

DESCRIPTION

Asyncronously connect to SMTP server, resolve MX, if needed, then send HELO => MAIL => RCPT => DATA => QUIT and return responce

FUNCTIONS

sendmail ... , cb => $cb->(OK,ERR)

Argument names are case insensitive. So, it may be calles as

    sendmail From => ..., To => ..., ...

and as

    sendmail from => ..., to => ..., ...

Arguments description are below

host => 'smtp.server'

SMTP server to use. Optional. By default will be resolved MX record

port => 2525

SMTP server port. Optional. By default = 25

server => 'some.server:25'

SMTP server. The same as pair of host:port

helo => 'hostname'

HELO message. Optional. By default = hostname()

from => 'mail@addr.ess'
to => 'mail@addr.ess'
to => [ 'mail@addr.ess', ... ]
data => 'Message body'
Message => 'Message body'

Message text. For message composing may be used, for ex: MIME::Lite

timeout => int

Use timeout during network operations

debug => 0 | 1

Enable connection debugging

cb => $cb->(OK,ERR)

Callback.

When $args{to} is a single argument:

    OK - latest response from server
    If OK is undef, then something failed, see ERR
    ERR - error response from server

When $args{to} is an array:

    OK - hash of success responces or undef.
    keys are addresses, values are responces

    ERR - hash of error responces.
    keys are addresses, values are responces

See examples

cv => AnyEvent->condvar

If passed, used as group callback operand

    sendmail ... cv => $cv, cb => sub { ...; };

is the same as

    $cv->begin;
    sendmail ... cb => sub { ...; $cv->end };

VARIABLES

$MAXCON [ = 10]

Maximum number of connections to any host. Default is 10

%MAXCON

Per-host configuration for maximum number of connection

Please note, host is hostname passed in argument, or resolved MX record.

So, if passed host = 'localhost'>, should be used $MAXCON{localhost}, if passed host = '127.0.0.1'>, should be used $MAXCON{'127.0.0.1'}

        # set default limit to 20
        $AnyEvent::SMTP::Client::MAXCON = 20;
        
        # don't limit localhost connections
        $AnyEvent::SMTP::Client::MAXCON{'localhost'} = 0;
        
        # big limit for one of gmail MX
        $AnyEvent::SMTP::Client::MAXCON{'gmail-smtp-in.l.google.com.'} = 100;

$ACTIVE

Number of currently active connections

%ACTIVE

Number of currently active connections per host

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.